Setup Python Environment

In my book, Hands-On Machine Learning with Scikit-Learn and Scientific Python Toolkits, I make use of libraries such as Pandas, Numpy, etc.

There are multiple ways to install the needed libraries.

For example you can:

Install via Miniforge (Virtual Environment)

First you need to install Miniforge on your computer. You fill find via the following link the right installer for your operating system and architecture. For example, they have installers for Windows, Linux, OSX (Intel) and OSX (Apple Silicon).

Now, that you have installed Miniforge. It is time to create a new Virtual Environment. Let's call it scikitbook, and we will be using Python version 3.6.

To create the environment, go to your terminal (for example, in OSX, find a program called Terminal and run it). Then type the following command into the terminal:

conda create -n scikitbook python=3.6

Note: Newer versions of Python should work too, but the code in the book is tested on 3.6, so let's stick to that version.

Now you need to activate the environment you have just created:

conda activate scikitbook

Then, you need to install Numpy, Scipy, Pandas, etc.

One way is to follow the instructions in page 27 in Hands-On Machine Learning with Scikit-Learn and Scientific Python Toolkits:

pip install --upgrade numpy==1.17.3
pip install --upgrade scipy==1.3.1
pip install --upgrade pandas==0.25.3
pip install --upgrade scikit-learn==0.22
pip install --upgrade matplotlib==3.1.2
pip install --upgrade seaborn==0.9.0

Alternatively, you can clone the book's github repo here, PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits. Then you can run the following command:

pip install --upgrade -r requirements.txt

You are all set now. Whenever you re-start your computer, you need to just run the following command to activate the environemnt:

conda activate scikitbook

Install via Anaconda (Virtual Environment)

The exact instructions above works for Anaconda too. The only difference is that you need to install the Anaconda/Miniconda from this link instead of Miniforge

Install without virtual environments

Just skip the virtual environment installations, and just install Python 3.6 on your system. Then run the following pip commands:

pip install --upgrade numpy==1.17.3
pip install --upgrade scipy==1.3.1
pip install --upgrade pandas==0.25.3
pip install --upgrade scikit-learn==0.22
pip install --upgrade matplotlib==3.1.2
pip install --upgrade seaborn==0.9.0

Again, you can use the book's github repo here, PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits. Then run the following command instead of the multiple pip commands above:

pip install --upgrade -r requirements.txt

Feel free to contact me if anything is not clear still.

Links to Amazon are affiliate links.