Python 3 code for the second edition of my book Machine learning: a probabilistic perspective. This is work in progress, so expect rough edges.
I have created IPython notebooks for each of the chapters. When you open a notebook, there will be a button at the top that says 'Open in colab'. If you click on this, it will start a virtual machine (VM) instance on Google Cloud Platform (GCP), running Colab, which has all the libraries you will need (e.g., scikit-learn, tensorflow 2, PyTorch) pre-installed. Furthermore, this is free, so all you need is a web browser and an internet connection.
If you select 'GPU' from the 'Runtime' menu at the top of Colab, many examples (especially those that use deep neural networks) will run much faster. The main limitation seems to be the 12GB memory limit. This should suffice for small experiments. For bigger jobs, you may need to buy cloud credit. Alternatively, you can run these notebooks locally on your desktop in Jupyter, but then you will have to install the packages yourself (see instructions below).
- Introduction
- Linear algebra
- Calculus
- Probability
- Information theory
- Bayesian statistics
- Frequentist statistics
- Statistical models
- Generalized linear models
- Deep neural networks
- Graphical models
- Visible generative models
- Latent generative models
- Gaussian processes
- Models for graphs, manifolds and clusters
- Reinforcement learning
Many of the figures in the book are generated by these scripts. To execute a script, cd (change directory) to the scripts folder, and then type 'python foo.py'. You can also run each script from inside a Python IDE (like Spyder). Many of the scripts create plots, which are saved to ../figures.
To run the scripts, we assume you have installed numpy, scipy, matplotlib, seaborn, pandas, scikit-learn, etc. (All of these are bundled with anaconda.) Some scripts rely on additional libraries, such as Tensorflow 2.0 and JAX. Scripts that need these libraries have filenames that end in tf and jax respectively. If you have problems running these, open up one of the notebooks above in Google Colab - which will have the various packages already installed - and then import the script.