Introduction
Extension for scikit-learn* is a free software AI accelerator designed to deliver up to 100X acceleration to existing workflows from scikit-learn (e.g. logistic regression models, random forests, support vector machines, among others), the most widely-used Python library for machine learning on tabular data.
This software acceleration is achieved through SIMD instructions, multi-threading, hardware-specific cache optimizations, and algorithmic optimizations.
Features:
Average speed up of 8.5x on both training and inference over scikit-learn, with equivalent mathematical accuracy.
Support for different hardware configurations, including GPUs and multi-GPU setups.
Easy to integrate into existing scikit-learn workflows without code modifications through monkeypatching, or as an API-compatible module
sklearnex.Can produce much faster predictions from decision-tree models generated by other libraries such as XGBoost or LightGBM.
See About the Extension for scikit-learn* for more information.
Quick Install
pip install scikit-learn-intelex
conda install -c conda-forge scikit-learn-intelex --override-channels
See the full Installation Instructions for more details.
Example Usage
import numpy as np
from sklearnex import patch_sklearn
patch_sklearn()
from sklearn.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
See Patching Utilities for more details.
import numpy as np
from sklearnex.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
Running on GPUs
Note: executing on GPU requires installing package scikit-learn-intelex-gpu, and comes with additional system software requirements - see GPU support for details.
import numpy as np
from sklearnex import patch_sklearn, config_context
patch_sklearn()
from sklearn.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
with config_context(target_offload="gpu:0"):
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
import os
os.environ["SCIPY_ARRAY_API"] = "1"
import numpy as np
import torch
from sklearnex import patch_sklearn
patch_sklearn()
from sklearn import config_context
from sklearn.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
X = torch.tensor(X, device="xpu")
with config_context(array_api_dispatch=True):
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
import numpy as np
from sklearnex import config_context
from sklearnex.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
with config_context(target_offload="gpu:0"):
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
import os
os.environ["SCIPY_ARRAY_API"] = "1"
import numpy as np
import torch
from sklearnex import config_context
from sklearnex.cluster import DBSCAN
X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
X = torch.tensor(X, device="xpu")
with config_context(array_api_dispatch=True):
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
See GPU support for other ways of executing on GPU.