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
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.