×

How to Install Scikit-Learn

Sklearn or Scikit-learn is a python library used for machine learning. It contains many features like classification, regression, clustering, and Dimensionality reduction algorithms. Sklearn is used to build machine learning models, so it cannot be used for manipulating Data and summarizing data.

It also provides efficient tools for machine learning and statistical modeling, including python regression, classification, and clustering. This library is built upon NumPy, SciPy, and Matplotlib in python. With this library it is easy to write machine learning algorithms.

This article lets us learn how to install the Scikit-learn library in python.

Before installing Sklearn, we first need to have python of version 2.6 or above, and also, you have to install NumPy and scipy from their official installers, then you have to install Sklearn.

For installing in Windows, you use the below command:

Pip install  scikit-learn

Or

pip install -U scikit-learn

You can also install scikit-learn using conda by taking the following command:

conda install scikit-learn

For installing on Mac OSX, you use the following command:

Pip install -U numpy scipy scikit-learn

For installing in Linux, you must first install the dependencies needed for python development.

So, if you are using Python 2, then you can use the following commands to install the requirements

sudo apt-get install build-essential python-dev python-setuptools \
 python-numpy python-scipy \
 libatlas-dev libatlas3gf-base

If you have Python 3, then you use the following commands to install the requirements

sudo apt-get install build-essential python3-dev python3-setuptools \
python3-NumPy python3-scipy \
libatlas-dev libatlas3gf-base


With these commands, the following dependencies will be automatically installed with scikit-learn

  • NumPy 1.13.3+
  • SciPy 0.19.1+
  • Joblib 0.11+
  • Threadpoolctl 2.0.0+

You can verify your installation by using the following command:

python -m pip show scikit-learn

Then you can check the dependencies and the scikit-learn installed in your system.

As you installed scikit-learn in the programs, we must import that library into the code by using the following command.

import sklearn

it is not always necessary to import all of the scikit-learn functions; instead, you can import the functions you need for that particular project using the following command.

from sklearn, import linear_model

For example, let us have a look at an example code given below:

From sklearn import datasets


iris= datasets.load_jarvis()


print(jarvis.data.shape)

Output

How to Install Scikit-Learn

In the above code, we loaded a data set with the name Jarvis, and it is a dataset of a flower, and it contains 150 observations with different lengths of flowers and printed shapes of that Data set; hence after execution, we got the output showing the size of (150, 4).

In that way, we can only import the required functions for a project.

Features of Scikit-learn

  • Supervised learning
  • Unsupervised learning
  • Reinforcement learning

Supervised learning: The data set must be in a labelled format so that the supervised learning algorithm gives a gathered function after analysis of the training data, which is used to map new data sets. And there are two types of problems in supervised learning: classification and regression.

Supervised learning algorithms:

  • k-nearest neighbours
  • linear regression
  • logistic regression
  • support vector machine (SVM)
  • decision trees

Unsupervised learning

This is also a machine learning algorithm which is also known as unlabelled. This is used to figure out the conclusion from datasets consisting of input data without labelled responses. Unsupervised learning uses only one method, clustering, to find the hidden patterns of a data set.

Unsupervised learning algorithms:

  • k-means
  • fuzzy k-means
  • hierarchical clustering
  • mixture of Gaussians

Reinforcement learning:

This is one of the basic machine learning algorithms; this is all about making decisions sequentially. So, every output depends based on the previous inputs. For example, we can take an online chess game.

Conclusion

Thus, by reading this article, you can understand what sklearn is, its importance of it and how to install sklearn in windows, mac, and Linux, and its dependencies in various ways. And, how to import and use that sklearn in the python projects and its shortcuts. Then we covered the features of sklearn, which are supervised, unsupervised, and reinforcement learning, including their features also. We also looked at an example program where we know how to load a data set and find its features. Therefore, with all these, we completed the basics of sklearn and its installation.


Related Topics

What is Python compiler GDB?

The source code of one programming language is converted into machine code, bytecode, or another programming language by a compiler, a specialised software. A compiler is a tool that converts high-level...

3 minutes read.

os.stat() method in Python

In Python, the os module provides the capacity to interact with the operating system. The operating system comes under the Python module. In this module, Python provides a specific feature...

3 minutes read.

Data Drop in Python

Introduction You'll understand how to delete a group of rows from a Pandas dataframe in this article.You can read this article on How to Drop Columns in Pandas to find out...

6 minutes read.

Python String isalpha() method

Python String isalpha() method The string.isalpha () method in Python returns a boolean value true if all characters in the  string are alphabetic else for any other value it returns false. Syntax isalpha()  Parameter NA Return This...

1 minute read.

Python isinstance() function

Python isinstance() function The isinstance() function in Python returns a Boolean value ‘True’ if the given object is of the specified type, otherwise it returns False. Syntax isinstance(object, classinfo) Parameter object: It is a required parameter which represents an object. classinfo: This...

1 minute read.

Adding a key-value pair to dictionary in Python

Python dictionaries are collections of unsorted key-value pairs. This article will examine a method for adding new key-value teams to an existing dictionary. Dictionary in Python With the aid of curly brackets...

3 minutes read.

Checking whether a String Contains a Set of Characters in python

In this tutorial, we will learn how to examine or check whether a string contains any set of characters or a substring and if it contains, we will learn how...

6 minutes read.

Conditional Expressions in Python

In Python conditional expression are sometimes referred to operator called as ternary operator. Not only Python supports ternary operator but many other programming languages supports it. Ternary operator are the...

2 minutes read.

Slicing of a String in Python

In this tutorial, we will learn about slicing of a string in Python. First of all, let us know what String and Slicing is. String String is a group of characters that...

6 minutes read.

How to print in the same line in Python?

How to print in the same line in python By default, the print function in Python takes us to the next line and prints the desired statement in the output. In this...

5 minutes read.

Python Boolean

In this article, you will learn the boolean variables in python, bool() function in python, and bool operators with examples, Boolean Objects in Python. There are the only two possible values...

6 minutes read.

Python Validator

Validator  The validator is a library available in the python programming language. The library in python consists of all the related modules which can be imported to perform the required operation....

3 minutes read.

How to Convert int to str in Python

How to Convert int to str in Python In the last article, we studied how we convert a variable with string datatype to integer datatype and discussed different data types available...

4 minutes read.

How to Install Matplotlib in Python?

How to Install Matplotlib in Python The speed at which the enormous amount of data is generating has become a huge aid in understanding what's going on currently in the market....

4 minutes read.

Poolmanager in Python

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

4 minutes read.

Python Basics

In this tutorial, we will learn about the basics of Python, a very famous programming language. This tutorial will help you understand the language better if you start with python....

8 minutes read.

Sublime Python

SUBLIME: A compact, cross-platform code editor called Sublime Text 3 (ST3) is well-known for its quickness, usability, and robust community support. Although it's a fantastic editor out of the box, its...

6 minutes read.

Insertion Sort using Python

Insertion sort is a type of sorting technique that is used for sorting an array with random elements. Using sorting methods, any unsorted array can be sorted into ascending or...

3 minutes read.

How to slice a list in python

When working with lists, we face situations where we may need a part of the list from one index to the other. Slicing is one of the simpler ways to...

5 minutes read.

Difference between Python 2 and Python 3

In this tutorial, we will learn the differences between two versions of python, that is, python version 2 and python version 3. Some basic differences include- Python 2 is the older version...

3 minutes read.