Member-only story

Speed up SkLearn Model Training by 10 or 100X… by just adding 2 lines of Code

Zex
3 min readApr 13, 2023

Photo by benjamin lehman on Unsplash

Scikit-learn is a widely used machine learning library. It contains a number of algorithms that we can use for classification, regression, clustering, etc. Sometimes it can be slow to train a sklearn model for a huge dataset. This post will show you how to use the Intel Scikit-learn extension to speed up the training and inference time.

Scikit-Learn-Intelex is an sklearn extension created by Intel to speed up the library performance on Intel CPU, without changing the existing code. The extension provides up to 100++ times speed up on model training and inference, depends on the algorithm, as shown in the image below:

Image Source: intel/scikit-learn-intelex: Intel(R) Extension for Scikit-learn is a seamless way to speed up your Scikit-learn application (github.com)

Let’s try the library to verify the claimed performance improvement. First create a virtual environment and then install the library:

pip install scikit-learn-intelex

We will use random forest regressor for the testing. To use the sklearn intel extension, we need to run patch the extension before importing the algorithm:

from sklearnex import patch_sklearn
patch_sklearn()

# After patch_sklearn() then we import the random forest…

Zex
Zex

Written by Zex

Machine Learning Engineer. Learn about Artificial Intelligence, Behavioral Economics, Music, and some random stuff

Responses (1)

Write a response

Thank you for sharing, much appreciated!