The Intel® Extension for Scikit-learn Getting Started
sample demonstrates how to use a support vector machine classifier from Intel® Extension for Scikit-learn* for digit recognition problem. All other machine learning algorithms available with Scikit-learn can be used in the similar way. Intel® Extension for Scikit-learn* speeds up scikit-learn applications. The acceleration is achieved through the use of the Intel® oneAPI Data Analytics Library (oneDAL) Intel oneAPI Data Analytics Library, which comes with AI Tools.
Area | Description |
---|---|
Category | Getting Started |
What you will learn | How to use a basic Intel® Extension for Scikit-learn* programming model for Intel CPUs |
Time to complete | 5 minutes |
In this sample, you will run a support vector classifier model from sklearn with oneDAL Daal4py library memory objects. You will also learn how to train a model and save the information to a file. Intel® Extension for Scikit-learn* depends on Intel® Daal4py. Daal4py is a simplified API to oneDAL that allows for fast usage of the framework suited for Data Scientists or Machine Learning users. Built to help provide an abstraction to oneDAL for direct usage or integration into one's own framework.
Optimized for | Description |
---|---|
OS | Ubuntu* 20.04 (or newer) |
Hardware | Intel Atom® processors Intel® Core™ processor family Intel® Xeon® processor family Intel® Xeon® Scalable processor family |
Software | AI Tools Intel® oneAPI Data Analytics Library (oneDAL) Joblib NumPy Matplotlib |
Note: AI and Analytics samples are validated on AI Tools Offline Installer. For the full list of validated platforms refer to Platform Validation.
This Getting Started sample code is implemented for CPU using the Python language. The example assumes you have Intel® Extension for Scikit-learn* installed inside a conda environment, similar to what is delivered with the installation of the Intel® Distribution for Python*. Intel® Extension for Scikit-learn* is available as a part of AI Tools.
You will need to download and install the following toolkits, tools, and components to use the sample.
1. Get AI Tools
Required AI Tools: Intel® Extension for Scikit-learn*
If you have not already, select and install these Tools via AI Tools Selector. AI and Analytics samples are validated on AI Tools Offline Installer. It is recommended to select Offline Installer option in AI Tools Selector.
Note: If Docker option is chosen in AI Tools Selector, refer to Working with Preset Containers to learn how to run the docker and samples.
2. (Offline Installer) Activate the AI Tools bundle base environment
If the default path is used during the installation of AI Tools:
source $HOME/intel/oneapi/intelpython/bin/activate
If a non-default path is used:
source <custom_path>/bin/activate
3. (Offline Installer) Activate relevant Conda environment
conda activate base
4. Clone the GitHub repository
git clone https://github.com/oneapi-src/oneAPI-samples.git
cd oneAPI-samples/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_SKLearn_GettingStarted
5. Install dependencies
Note: Before running the following commands, make sure your Conda/Python environment with AI Tools installed is activated
pip install -r requirements.txt
pip install notebook
For Jupyter Notebook, refer to Installing Jupyter for detailed installation instructions.
Note: Before running the sample, make sure Environment Setup is completed.
Go to the section which corresponds to the installation method chosen in AI Tools Selector to see relevant instructions:
1. Register Conda kernel to Jupyter Notebook kernel
If the default path is used during the installation of AI Tools:
$HOME/intel/oneapi/intelpython/envs/base/bin/python -m ipykernel install --user --name=base
If a non-default path is used:
<custom_path>/bin/python -m ipykernel install --user --name=base
2. Launch Jupyter Notebook
jupyter notebook --ip=0.0.0.0
3. Follow the instructions to open the URL with the token in your browser
4. Select the Notebook
Intel_Extension_For_SKLearn_GettingStarted.ipynb
5. Change the kernel to base
6. Run every cell in the Notebook in sequence
Note: Before running the instructions below, make sure your Conda/Python environment with AI Tools installed is activated
1. Register Conda/Python kernel to Jupyter Notebook kernel
For Conda:
<CONDA_PATH_TO_ENV>/bin/python -m ipykernel install --user --name=<your-env-name>
To know <CONDA_PATH_TO_ENV>, run conda env list
and find your Conda environment path.
For PIP:
python -m ipykernel install --user --name=<your-env-name>
2. Launch Jupyter Notebook
jupyter notebook --ip=0.0.0.0
3. Follow the instructions to open the URL with the token in your browser
4. Select the Notebook
Intel_Extension_For_SKLearn_GettingStarted.ipynb
5. Change the kernel to <your-env-name>
6. Run every cell in the Notebook in sequence
AI Tools Docker images already have Get Started samples pre-installed. Refer to Working with Preset Containers to learn how to run the docker and samples.
You should see printed output for cells (with similar numbers) and an accuracy result.
Model accuracy on test data: 0.9833333333333333
[CODE_SAMPLE_COMPLETED_SUCCESFULLY]
Code samples are licensed under the MIT license. See License.txt for details.
Third party program Licenses can be found here: third-party-programs.txt
*Other names and brands may be claimed as the property of others. Trademarks