You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Intel® Python Scikit-learn Extension Getting Started Sample
1
+
# Intel® Extension for Scikit-learn Getting Started Sample
2
2
3
-
The `Intel® Python Scikit-learn Extension 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](https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onedal.html), which comes with [Intel® AI Analytics Toolkit (AI Kit)](https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html).
3
+
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](https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onedal.html), which comes with [AI Tools](https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html).
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.
16
+
16
17
## Prerequisites
17
18
18
19
| Optimized for | Description
19
20
| :--- | :---
20
21
| OS | Ubuntu* 20.04 (or newer)
21
22
| Hardware | Intel Atom® processors <br> Intel® Core™ processor family <br> Intel® Xeon® processor family <br> Intel® Xeon® Scalable processor family
You can refer to the oneAPI [product page](https://software.intel.com/en-us/oneapi) for toolkit installation and the Toolkit *[Get Started with the Intel® AI Analytics Toolkit for Linux*
25
-
](https://software.intel.com/en-us/get-started-with-intel-oneapi-linux-get-started-with-the-intel-ai-analytics-toolkit)* for post-installation steps and scripts.
26
-
27
-
oneDAL is ready for use once you finish the AI Kit installation and have run the post installation script.
23
+
| Software | AI Tools <br> Intel® oneAPI Data Analytics Library (oneDAL) <br> Joblib <br> NumPy <br> Matplotlib
28
24
25
+
> **Note**: AI and Analytics samples are validated on AI Tools Offline Installer. For the full list of validated platforms refer to [Platform Validation](https://github.com/oneapi-src/oneAPI-samples/tree/master?tab=readme-ov-file#platform-validation).
29
26
30
27
## Key Implementation Details
31
28
32
-
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* as part of the [Intel® AI Analytics Toolkit](https://software.intel.com/en-us/oneapi/ai-kit). Intel® Extension for Scikit-learn* is available as a part of Intel® AI Analytics Toolkit (AI kit).
29
+
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.
33
30
34
31
## Environment Setup
35
32
36
-
1. If you have not already done so, activate the AI Tools bundle base environment. If you used the default location to install AI Tools, open a terminal and type the following
33
+
You will need to download and install the following toolkits, tools, and components to use the sample.
34
+
35
+
**1. Get AI Tools**
36
+
37
+
Required AI Tools: Intel® Extension for Scikit-learn*
38
+
39
+
If you have not already, select and install these Tools via [AI Tools Selector](https://www.intel.com/content/www/us/en/developer/tools/oneapi/ai-tools-selector.html). AI and Analytics samples are validated on AI Tools Offline Installer. It is recommended to select Offline Installer option in AI Tools Selector.
40
+
41
+
>**Note**: If Docker option is chosen in AI Tools Selector, refer to [Working with Preset Containers](https://github.com/intel/ai-containers/tree/main/preset) to learn how to run the docker and samples.
42
+
43
+
**2. (Offline Installer) Activate the AI Tools bundle base environment**
44
+
<!-- this step is from AI Tools GSG, please don't modify unless GSG is updated -->
45
+
If the default path is used during the installation of AI Tools:
cd oneAPI-samples/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_SKLearn_GettingStarted
48
65
```
49
-
source activate base
50
-
pip install -r requirements.txt
66
+
67
+
**5. Install dependencies**
68
+
>**Note**: Before running the following commands, make sure your Conda/Python environment with AI Tools installed is activated
69
+
51
70
```
71
+
pip install -r requirements.txt
72
+
pip install notebook
73
+
```
74
+
For Jupyter Notebook, refer to [Installing Jupyter](https://jupyter.org/install) for detailed installation instructions.
75
+
76
+
## Run the Sample
77
+
>**Note**: Before running the sample, make sure [Environment Setup](https://github.com/oneapi-src/oneAPI-samples/tree/master/AI-and-Analytics/Getting-Started-Samples/INC-Quantization-Sample-for-PyTorch#environment-setup) is completed.
52
78
53
-
2a. Activate Conda without Root Access (Optional)
79
+
Go to the section which corresponds to the installation method chosen in [AI Tools Selector](https://www.intel.com/content/www/us/en/developer/tools/oneapi/ai-tools-selector.html) to see relevant instructions:
By default, the Intel® AI Analytics Toolkit is installed in the inteloneapi folder, which requires root privileges to manage it. If you would like to bypass using root access to manage your conda environment, then you can clone and activate your desired conda environment using the following commands.
84
+
### AI Tools Offline Installer (Validated)
85
+
86
+
**1. Register Conda kernel to Jupyter Notebook kernel**
87
+
88
+
If the default path is used during the installation of AI Tools:
<!-- add other flags to jupyter notebook command if needed, such as port 8888 or allow-root -->
99
+
```
100
+
jupyter notebook --ip=0.0.0.0
101
+
```
102
+
**3. Follow the instructions to open the URL with the token in your browser**
67
103
68
-
1. Change to the sample directory.
69
-
2. Install Jupyter Notebook with the proper kernel.
70
-
```
71
-
conda install jupyter nb_conda_kernels
72
-
```
104
+
**4. Select the Notebook**
105
+
```
106
+
Intel_Extension_For_SKLearn_GettingStarted.ipynb
107
+
```
108
+
**5. Change the kernel to `base`**
109
+
<!-- specify relevant kernel name(s), for example `pytorch` -->
110
+
111
+
**6. Run every cell in the Notebook in sequence**
73
112
74
-
#### View in Jupyter Notebook
113
+
### Conda/PIP
114
+
> **Note**: Before running the instructions below, make sure your Conda/Python environment with AI Tools installed is activated
75
115
76
-
>**Note**: This distributed execution cannot be launched from Jupyter Notebook, but you can still view inside the notebook to follow the included write-up and description.
116
+
**1. Register Conda/Python kernel to Jupyter Notebook kernel**
117
+
<!-- keep placeholders in this step, user could use any name for Conda/PIP env -->
<!-- add other flags to jupyter notebook command if needed, such as port 8888 or allow-root -->
130
+
```
131
+
jupyter notebook --ip=0.0.0.0
132
+
```
133
+
**3. Follow the instructions to open the URL with the token in your browser**
88
134
135
+
**4. Select the Notebook**
136
+
<!-- add sample file name -->
137
+
```
138
+
Intel_Extension_For_SKLearn_GettingStarted.ipynb
139
+
```
140
+
**5. Change the kernel to `<your-env-name>`**
141
+
<!-- leave <your-env-name> as a placeholder as user could choose any name for the env -->
89
142
90
-
#### Troubleshooting
143
+
**6. Run every cell in the Notebook in sequence**
91
144
92
-
If you receive an error message, troubleshoot the problem using the **Diagnostics Utility for Intel® oneAPI Toolkits**. The diagnostic utility provides configuration and system checks to help find missing dependencies, permissions errors, and other issues. See the *[Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html)* for more information on using the utility.
145
+
### Docker
146
+
AI Tools Docker images already have Get Started samples pre-installed. Refer to [Working with Preset Containers](https://github.com/intel/ai-containers/tree/main/preset) to learn how to run the docker and samples.
93
147
94
148
## Example Output
95
149
@@ -113,8 +167,10 @@ Model accuracy on test data: 0.9833333333333333
113
167
## License
114
168
115
169
Code samples are licensed under the MIT license. See
116
-
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt).
0 commit comments