How to Install Scikit-learn on Ubuntu 20.04


Today I will walk you through the steps to install Scikit-learn on your Ubuntu 20.04, you will get step-by-step instructions on how you can Install Scikit-learn on your ubuntu. Now, before starting the installation, let’s see what Scikit-learn is.

What is Scikit-learn – Scikit-learn is a free software library for the python programming language. It provides machine learning algorithms for data mining tasks, including classification, regression, clustering, dimensionality reduction, and model selection. Scikit-learn provides a simple interface to these algorithms so that they can be applied to various real-world problems.

[lyte id=’lxgxxRG_V5A’ /]

Update and Upgrade

Before starting the installation of sci-kit learn make sure to update and upgrade your apt packages using the commands –

sudo apt-get update 
sudo apt-get upgrade

Once done, you can now proceed to the installation process, do note that you will need sudo permissions in order to install sci-kit learn, so make sure you have sudo permissions.

Install Requirements

To be able to run Sci-kit Learn you will need Numpy, Scipy and the latest version of Python installed on your ubuntu, if you already have the required packages installed then scroll down to the installation process.

If you don’t then here are the steps to install pip3, Scipy, Numpy, and Python3 –

Install / Update Python3 –

To install or update Python you will need to use the apt-get command in the terminal, open the terminal and enter the following command – 

sudo apt-get install python3 -y

This command will install the latest version of python3, which we will need to install Sci-kit Learn.

Install pip3 –

To be able to install Sci-kit, scipy, and Numpy you will need pip3, now to install pip3 or to update it to the latest version you can use this command –

sudo apt-get -y install python3-pip

Install Numpy and Scipy –

Once pip3 is installed you can now install Numpy and Scipy using the commands given here – 

To install Numpy use this command –

python3 -m pip install --user numpy

To install Scipy use this command –

python3 -m pip install --user scipy

Once all the requirements are satisfied for the installation of Sci-kit Learn, you can now start the installation of Scikit.

Install Sci-kit Learn

The installation process of Sci-kit Learn is very easy, all you need to do is enter a single command, the command to install sci-kit learn on ubuntu 20.04 is – 

pip3 install -U scikit-learn

scikit-learn install command

Once the installation of Scikit finishes, you can verify whether sci-kit learn was installed properly or not by entering this command in the terminal –

python3 -m pip show scikit-learn

After you enter this command in the terminal window, you will see an output in the terminal that will say the name of the package that is “scikit-learn” and the version of the package. If it says command not found that means you did something wrong.

verify scikit learn installation

Try to install it once again if you are facing any problem while installing scikit-learn.

Install Sci-kit Learn using Conda

Now if you have Anaconda installed on your ubuntu then you can easily install Sci-kit learn using a single command, if you don’t have Anaconda installed on your ubuntu then you can follow this tutorial on Installing Anaconda on Ubuntu 20.04, which will show you how you can install Anaconda.

Now to install Sci-kit Learn using conda you can enter this command in the terminal where conda is active –

conda install scikit-learn

This command will install Sci-kit on your ubuntu using conda, now to verify the installation enter the command “conda list scikit-learn”.

Using Sci-kit Learn

To use sci-kit learn you will need to use import, use “import sklearn” to use Scikit learn on your projects.

Avoid Conflicts

If you don’t want scikit to learn to conflict with other packages installed on your ubuntu then what you can do is create a virtual Python environment or a Conda Environment, this will keep the scikit learn separate from other packages on your ubuntu thus avoiding conflicts from them.

Installing Scikit-learn in a virtual environment will be a better idea as you don’t want conflicts creating problems with the installation or regular usage.

And that’s it, that is how you can install Sci-kit Learn on your ubuntu 20.04 using python and conda, if you are facing any problem while installing scikit-learn then comment below, thank you.

Recent Content