Quick Start

Get ready to elevate your scikit-learn code with Intel® Extension for Scikit-learn* and experience the benefits of accelerated performance in just a few simple steps.

Compatibility with Scikit-learn*

Intel(R) Extension for Scikit-learn is compatible with the last four versions of scikit-learn.

Integrate Intel® Extension for Scikit-learn*

Patching

Once you install Intel*(R) Extension for Scikit-learn*, you replace algorithms that exist in the scikit-learn package with their optimized versions from the extension. This action is called patching. This is not a permanent change so you can always undo the patching if necessary.

To patch Intel® Extension for Scikit-learn, use one of these methods:

Method

Action

Use a flag in the command line

Run this command:

python -m sklearnex my_application.py

Modify your script

Add the following lines:

from sklearnex import patch_sklearn
patch_sklearn()

Import an estimator from the sklearnex module

Run this command:

from sklearnex.neighbors import NearestNeighbors

These patching methods are interchangeable. They support different enabling scenarios while producing the same result.

Example

This example shows how to patch Intel(R) extension for Scikit-Learn by modifing your script. To make sure that patching is registered by the scikit-learn estimators, always import scikit-learn after these lines.

Example: Drop-In Patching
  import numpy as np
  from sklearnex import patch_sklearn
  patch_sklearn()

  # You need to re-import scikit-learn algorithms after the patch
  from sklearn.cluster import KMeans

  # The use of the original Scikit-learn is not changed
  X = np.array([[1,  2], [1,  4], [1,  0],
              [10, 2], [10, 4], [10, 0]])
  kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
  print(f"kmeans.labels_ = {kmeans.labels_}")

Global Patching

You can also use global patching to patch all your scikit-learn applications without any additional actions.

Before you begin, make sure that you have read and write permissions for Scikit-learn files.

With global patching, you can:

Task

Action

Note

Patch all supported algorithms

Run this command:

python -m sklearnex.glob patch_sklearn

If you run the global patching command several times with different parameters, then only the last configuration is applied.

Patch selected algorithms

Use --algorithm or -a keys with a list of algorithms to patch. For example, to patch only SVC and RandomForestClassifier estimators, run

python -m sklearnex.glob patch_sklearn -a svc random_forest_classifier

Enable global patching via code

Use the patch_sklearn function with the global_patch argument:

from sklearnex import patch_sklearn
patch_sklearn(global_patch=True)
import sklearn

After that, Scikit-learn patches is enabled in the current application and in all others that use the same environment.

Disable patching notifications

Use --no-verbose or -nv keys:

python -m sklearnex.glob patch_sklearn -a svc random_forest_classifier -nv

Disable global patching

Run this command:

python -m sklearnex.glob unpatch_sklearn

Disable global patching via code

Use the global_patch argument in the unpatch_sklearn function

from sklearnex import unpatch_sklearn
unpatch_sklearn(global_patch=True)

Tip

If you clone an environment with enabled global patching, it will already be applied in the new environment.

Unpatching

To undo the patch (also called unpatching) is to return scikit-learn to original implementation and replace patched algorithms with the stock scikit-learn algorithms.

To unpatch successfully, you must reimport the scikit-learn package:

sklearnex.unpatch_sklearn()
# Re-import scikit-learn algorithms after the unpatch
from sklearn.cluster import KMeans

Installation

Tip

To prevent version conflicts, we recommend creating and activating a new environment for Intel® Extension for Scikit-learn*.

Install from PyPI

Recommended by default.

To install Intel® Extension for Scikit-learn*, run:

pip install scikit-learn-intelex

Supported Configurations

OS / Python version

Python 3.8

Python 3.9

Python 3.10

Python 3.11

Python 3.12

Linux* OS

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

Windows* OS

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

[CPU, GPU]

Install from Anaconda* Cloud

To prevent version conflicts, we recommend installing scikit-learn-intelex into a new conda environment.

Recommended by default.

To install, run:

conda install scikit-learn-intelex -c conda-forge
Supported Configurations

OS / Python version

Python 3.8

Python 3.9

Python 3.10

Python 3.11

Python 3.12

Linux* OS

[CPU]

[CPU]

[CPU]

[CPU]

[CPU]

Windows* OS

[CPU]

[CPU]

[CPU]

[CPU]

[CPU]

Build from Sources

See Installation instructions to build Intel® Extension for Scikit-learn* from the sources.

Install Intel*(R) AI Tools

Download the Intel AI Tools here. The extension is already included.

Release Notes

See the Release Notes for each version of Intel® Extension for Scikit-learn*.

System Requirements

Hardware Requirements

All processors with x86 architecture with at least one of the following instruction sets:

  • SSE2

  • SSE4.2

  • AVX2

  • AVX512

Note

ARM* architecture is not supported.

Tip

Intel(R) processors provide better performance than other CPUs. Read more about hardware comparison in our blogs.

Software Requirements

  • Linux* OS: Ubuntu* 18.04 or newer

  • Windows* OS 10 or newer

  • Windows* Server 2019 or newer

Intel(R) Extension for Scikit-learn is compatible with the last four versions of scikit-learn:

  • 1.0.X

  • 1.1.X

  • 1.2.X

  • 1.3.X

Memory Requirements

By default, algorithms in Intel® Extension for Scikit-learn* run in the multi-thread mode. This mode uses all available threads. Optimized scikit-learn algorithms can consume more RAM than their corresponding unoptimized versions.

Algorithm

Single-thread mode

Multi-thread mode

SVM

Both Scikit-learn and Intel® Extension for Scikit-learn* consume approximately the same amount of RAM.

In Intel® Extension for Scikit-learn*, an algorithm with N threads consumes N times more RAM.

In all Intel® Extension for Scikit-learn* algorithms with GPU support, computations run on device memory. The device memory must be large enough to store a copy of the entire dataset. You may also require additional device memory for internal arrays that are used in computation.

See also

Samples