An open API service indexing awesome lists of open source software.

https://github.com/uxlfoundation/scikit-learn-intelex

Extension for Scikit-learn is a seamless way to speed up your Scikit-learn application
https://github.com/uxlfoundation/scikit-learn-intelex

ai-inference ai-machine-learning ai-training analytics big-data data-analysis gpu hacktoberfest machine-learning machine-learning-algorithms oneapi python scikit-learn swrepo

Last synced: 15 days ago
JSON representation

Extension for Scikit-learn is a seamless way to speed up your Scikit-learn application

Awesome Lists containing this project

README

          

# Extension for scikit-learn*

Speed up your scikit-learn applications for CPUs and GPUs across single- and multi-node configurations

[Releases](https://github.com/uxlfoundation/scikit-learn-intelex/releases)   |   [Documentation](https://uxlfoundation.github.io/scikit-learn-intelex/)   |   [Examples](https://uxlfoundation.github.io/scikit-learn-intelex/latest/samples.html)   |   [Support](https://uxlfoundation.github.io/scikit-learn-intelex/latest/support.html)   |  [License](https://github.com/uxlfoundation/scikit-learn-intelex/blob/master/LICENSE)   

[![Build Status](https://dev.azure.com/daal/daal4py/_apis/build/status/CI?branchName=main)](https://dev.azure.com/daal/daal4py/_build/latest?definitionId=9&branchName=main)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/21716/badge.svg)](https://scan.coverity.com/projects/daal4py)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/uxlfoundation/scikit-learn-intelex/badge)](https://securityscorecards.dev/viewer/?uri=github.com/uxlfoundation/scikit-learn-intelex)
[![Join the community on GitHub Discussions](https://badgen.net/badge/join%20the%20discussion/on%20github/black?icon=github)](https://github.com/uxlfoundation/scikit-learn-intelex/discussions)
[![PyPI Version](https://img.shields.io/pypi/v/scikit-learn-intelex)](https://pypi.org/project/scikit-learn-intelex/)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/scikit-learn-intelex)](https://anaconda.org/conda-forge/scikit-learn-intelex)
[![python version](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)
[![scikit-learn supported versions](https://img.shields.io/badge/sklearn-1.6%20%7C%201.7%20%7C%201.8%20%7C%201.9-blue)](https://img.shields.io/badge/sklearn-1.6%20%7C%201.7%20%7C%201.8%20%7C%201.9-blue)

---

## Overview

Extension for scikit-learn is a **free software AI accelerator** designed to deliver up to **100X** acceleration to existing workflows from [scikit-learn](https://scikit-learn.org) (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](https://scikit-learn.org), with equivalent mathematical accuracy.
* Support for different hardware configurations, including [GPUs](https://uxlfoundation.github.io/scikit-learn-intelex/latest/oneapi-gpu.html) and [multi-GPU](https://uxlfoundation.github.io/scikit-learn-intelex/latest/distributed-mode.html) setups.
* Easy to integrate into existing [scikit-learn](https://scikit-learn.org) workflows without code modifications through [monkeypatching](https://uxlfoundation.github.io/scikit-learn-intelex/latest/patching.html), or as an API-compatible module `sklearnex`.
* Can produce [much faster predictions](https://uxlfoundation.github.io/scikit-learn-intelex/latest/model_builders.html) from decision-tree models generated by other libraries such as [XGBoost](https://xgboost.ai/) or [LightGBM](https://lightgbm.readthedocs.io/en/latest/index.html).

## Acceleration

![](doc/sources/_static/scikit-learn-acceleration.PNG)

[Benchmarks code](https://github.com/IntelPython/scikit-learn_bench)

## Optimizations

Easiest way to benefit from accelerations from the extension is by patching [scikit-learn](https://scikit-learn.org) with it:

- **Enable CPU optimizations**

```python
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)
```

- **Enable GPU optimizations**

_Note: executing on GPU has [additional system software requirements](https://www.intel.com/content/www/us/en/developer/articles/system-requirements/intel-oneapi-dpcpp-system-requirements.html) - see [details](https://uxlfoundation.github.io/scikit-learn-intelex/latest/oneapi-gpu.html)._

```python
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)
```

:eyes: Read about [other ways to patch scikit-learn](https://uxlfoundation.github.io/scikit-learn-intelex/latest/patching.html).

:eyes: Check out available [notebooks](https://github.com/uxlfoundation/scikit-learn-intelex/tree/master/examples/notebooks) for more examples.

### Usage without patching

Alternatively, all functionalities are also available under a separate module which can be imported directly, without involving any patching.

* To run on CPU:

```python
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)
```

* To run on GPU:

```python
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)
```

## Installation

To install Extension for scikit-learn, run:

```shell
pip install scikit-learn-intelex
```

Package is also offered through other channels such as conda-forge. See all installation instructions in the [Installation Guide](https://uxlfoundation.github.io/scikit-learn-intelex/latest/installation.html).

## Documentation

* [Technical documentation](https://uxlfoundation.github.io/scikit-learn-intelex/latest/index.html)
* [Release Notes](https://github.com/uxlfoundation/scikit-learn-intelex/releases)
* [Medium Blog Posts](https://uxlfoundation.github.io/scikit-learn-intelex/latest/blogs.html)

### Extension and oneDAL

Acceleration in patched scikit-learn classes is achieved by replacing calls to [scikit-learn](https://scikit-learn.org) with calls to oneDAL (oneAPI Data Analytics Library) behind the scenes:
- [oneAPI Data Analytics Library](https://github.com/uxlfoundation/oneDAL)

## How to Contribute

We welcome community contributions, check our [Contributing Guidelines](https://uxlfoundation.github.io/scikit-learn-intelex/latest/contribute.html) to learn more.

------------------------------------------------------------------------
\* The Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others.