Most of the notebooks and source code in this repository are based on the book: Machine Learning with PyTorch and Scikit-Learn by Sebastian Raschka, Yuxi (Hayden) Liu and Vahid Mirjalili.
This repository uses Docker container with all the required packages and libraries to run the code and jupyter notebooks. You can use the provided Dockerfile to build the image and run the container. The Dockerfile is provided in the root of the repository.
- install Docker on your machine
- see Docker Installation
bash run-docker.sh # run interactive container/Terminal
bash run-jupyter.sh # run jupyter notebook server
This notebook and the original book is written for Python version >= 3.7.0
, and it is recommended
you use the most recent version of Python 3 and the machine learning packages and libraries that are currently available.
- update the requirements.txt file to include the required packages
The Anaconda installer can be downloaded at https://docs.anaconda.com/anaconda/install/, and an Anaconda quick start-guide is available at https://docs.anaconda.com/anaconda/user-guide/getting-started/.
After successfully installing Anaconda/Miniconda, we can create virtual environment with a particular version of Python and install new Python packages in that environment using the following commands:
conda update conda
conda env list # list current environments
conda env remove -n <environment_name> # remove existing environment
- ml.yml file is provided with the repository
- this automates the createtion of new environemnt and installation of dependent packages
- if needed, change prefix to the right path where you want the environment and packages to install
- the provided file expects you've miniconda in your home folder, e.g., /Users/rbasnet/miniconda
conda env create -f ml.yml
conda create -n ml python=3.10 # create new ml environment
conda env list # list all the avialable virtual environments
conda activate ml #activate ml environment
conda install <SomePackage> #install packages
conda deactivate # exit out the current environment
conda activate ml
conda update <SomePackage>
conda deactivate
Throughout this book, we will mainly use NumPy's multi-dimensional arrays to store and manipulate data. Occasionally, we will make use of pandas, which is a library built on top of NumPy that provides additional higher level data manipulation tools that make working with tabular data even more convenient. To augment our learning experience and visualize quantitative data, which is often extremely useful to intuitively make sense of it, we will use the very customizable matplotlib library.
The version numbers of the major Python packages that were used for writing this book are listed below. Please make sure that the version numbers of your installed packages are equal to, or greater than, those version numbers to ensure the code examples run correctly:
- NumPy >= 1.17.4
- SciPy >= 1.3.1
- scikit-learn >= 0.22.0
- matplotlib >= 3.1.0
- pandas >= 0.25.3
- you can use
python_environment_check.py
file to check if correct version of required packages are installed
conda activate ml
conda install numpy
conda install scipy
conda install scikit-learn
conda install matplotlib
conda install pandas
Jupyter notebooks allow us to have everything in one place: Our code, the results from executing the code, plots of our data, and documentation that supports the handy Markdown and powerful LaTeX syntax! Notebooks are provided in notebooks folder. You can run the notebooks using Jupyter Notebook server.
We can use the conda command if we have Anaconda or Miniconda installed:
conda activate ml
conda install jupyter notebook
conda install -c conda-forge retrolab
- on Windows use, Git Bash
- using terminal to clone this repository
- to open a Jupyter notebook, we
cd
to the directory that contains your notebooks, e.g,.
cd ~/Python-Machine-Learning
bash run-jupyter.sh
Jupyter will start in our default browser (typically running at http://localhost:8888/). Browse into the notebooks folder and simply select the notebook you wish to open from the Jupyter menu.
- use the Table of Contents to navigate through the notebooks
For more information about the Jupyter notebook, I recommend the Jupyter Beginner Guide and Jupyter Notebook Basics.