Open In App

How to Install Scikit-Learn on Linux?

In this article, we are going to see how to install Scikit-Learn on Linux. Scikit-Learn is a python open source library for predictive data analysis. It is built on NumPy, SciPy, and matplotlib. It is written in Python, Cython, C, and C++ language. It is available for Linux, Unix, Windows, and Mac.

Method 1: Installing Scikit-Learn from source

Step 1: Installing python3 and the essentials dependencies to build the Scikit-learn.



sudo apt-get install build-essential python3-dev python3-pip

installing python

Step 2: Got the scikit-learn repository and clone it using the following command.



git clone git://github.com/scikit-learn/scikit-learn.git --depth 1
cd scikit-learn

Downloading Scikit-Learn

Step 3: Create a virtual environment for separate installation of Scikit-learn.

To install the python3-virtualenv tool, if you have not installed it yet.

sudo apt install python3.8-venv

Run the following command to create and activate the virtual environment.

python3 -m venv geeks-env

This will create a virtual environment called geeks-env

source geeks-env/bin/activate

Activating virtual environment

The above command will activate the virtual environment.

Step 4: Now, Install NumPy, SciPy, and Cython and build the package with pip in Editable mode:

pip install numpy scipy cython

installing  NumPy, SciPy, and Cython

Building the package:

pip install --verbose --no-build-isolation --editable .

building from source

Step 5: Verifying the installation.

python3 -c "import sklearn; sklearn.show_versions()"

Verifying the installation

Method 2: Installing Scikit-Learn using the pip command

Step 1: Install Scikit-learn using the following pip installation command:

pip3 install -U scikit-learn

installing scikit learn

Step 2: Verify the installation by running the following command:

python3 -m pip show scikit-learn

successfully installed scikit-learn

Article Tags :