Book Image

Machine Learning with scikit-learn Quick Start Guide

By : Kevin Jolly
Book Image

Machine Learning with scikit-learn Quick Start Guide

By: Kevin Jolly

Overview of this book

Scikit-learn is a robust machine learning library for the Python programming language. It provides a set of supervised and unsupervised learning algorithms. This book is the easiest way to learn how to deploy, optimize, and evaluate all of the important machine learning algorithms that scikit-learn provides. This book teaches you how to use scikit-learn for machine learning. You will start by setting up and configuring your machine learning environment with scikit-learn. To put scikit-learn to use, you will learn how to implement various supervised and unsupervised machine learning models. You will learn classification, regression, and clustering techniques to work with different types of datasets and train your models. Finally, you will learn about an effective pipeline to help you build a machine learning project from scratch. By the end of this book, you will be confident in building your own machine learning models for accurate predictions.
Table of Contents (10 chapters)

Installing scikit-learn

There are two ways in which you can install scikit-learn on your personal device:

  • By using the pip method
  • By using the Anaconda method

The pip method can be implemented on the macOS/Linux Terminal or the Windows PowerShell, while the Anaconda method will work with the Anaconda prompt.

Choosing between these two methods of installation is pretty straightforward:

  • If you would like all the common Python package distributions for data science to be installed in one environment, the Anaconda method works best
  • If you would like to build you own environment from scratch for scikit-learn, the pip method works best (for advanced users of Python)
This book will be using Python 3.6 for all the code that is displayed throughout every chapter, unless mentioned otherwise.

The pip method

Scikit-learn requires a few packages to be installed on your device before you can install it. These are as follows:

  • NumPy: Version 1.8.2 or greater
  • SciPy: Version 0.13.3 or greater

These can be installed using the pip method by using the following commands:

pip3 install NumPy
pip3 install SciPy

Next, we can install scikit-learn using the following code:

pip3 install scikit-learn

Additionally, if you already have scikit-learn installed on your device and you simply want to upgrade it to the latest version, you can use the following code:

pip3 install -U scikit-learn
The version of scikit-learn implemented in the book is 0.19.1.

The Anaconda method

In the event that you have installed Python using the Anaconda distribution, you can install scikit-learn by using the following code in the Anaconda prompt:

The first step is to install the dependencies:

conda install NumPy
conda install SciPy

Next, we can install scikit-learn by using the following code:

conda install scikit-learn

Additionally, if you already have scikit-learn installed with the Anaconda distribution, you can upgrade it to the latest version by using the following code in the Anaconda prompt:

conda update scikit-learn
When upgrading or uninstalling scikit-learn that has been installed with Anaconda, avoid using the pip method at all costs as doing so is most likely going to fail upgrading or removing all the required files. Stick with either the pip method or the Anaconda method in order to maintain consistency.

Additional packages

In this section, we will talk about the packages that we will be installing outside of scikit-learn that will be used throughout this book.

Pandas

To install Pandas, you can use either the pip method or the Anaconda method, as follows:

Pip method:

pip3 install pandas

Anaconda method:

conda install pandas

Matplotlib

To install matplotlib, you can use either the pip method or the Anaconda method, as follows:

Pip method:

pip3 install matplotlib

Anaconda method:

conda install matplotlib

Tree

To install tree, you can use either the pip method or the Anaconda method, as follows:

Pip method:

pip3 install tree

Anaconda method:

conda install tree

Pydotplus

To install pydotplus, you can use either the pip method or the Anaconda method, as follows:

Pip method:

pip3 install pydotplus

Anaconda method:

conda install pydotplus

Image

To install Image, you can use either the pip method or the Anaconda method, as follows:

Pip method:

pip3 install Image

Anaconda method:

conda install Image