Python code for "Machine learning: a probabilistic perspective" (2nd edition)

Overview

pyprobml

Python 3 code for my new book series Probabilistic Machine Learning. This is work in progress, so expect rough edges. Getting less rough...

Jupyter notebooks

For each chapter there are one or more accompanying Jupyter notebooks that cover some of the material in more detail. 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. This has most of the libraries you will need (e.g., scikit-learn, JAX) pre-installed, and gives you access to a free GPU. See this tutorial for details on how to use Colab.

Book 1 (PML: An Introduction)

See this link for a list of notebooks.

Book 2 (PML: Advanced topics)

See this link for a list of notebooks.

Running scripts to make individual figures

Many of the figures in the book are generated by various scripts. To run these, first clone this gihub repo. (For some tutorials on how to use github, see github guides.) Then, to manually execute an individual script from the command line, follow this example:

export PYPROBML=/Users/kpmurphy/github/pyprobml // set this to the directory where you downloaded this repo
cd $PYPROBML
python3 scripts/softmax_plot.py // writes to /Users/kpmurphy/github/pyprobml/figures/softmax_temp.pdf

The notebook for each chapter uses these scripts to recreate all the figures for that chapter.

Viewing the scripts

To browse the code using VScode instead of the gihub file viewer, you can just replace https://github.com/probml/pyprobml/tree/master/scripts with https://github1s.com/probml/pyprobml/tree/master/scripts (see this tweet). The output should look like this:

How to contribute

See this guide for how to contribute code.

Acknowledgements

I would like to thank the following people for contributing to the code (list autogenerated from this page):

murphyk mjsML ashishpapanai Duane321 animesh-007 Nirzu97 Drishttii always-newbie161 nappaillav jdf22 shivaditya-meduri karalleyna gerdm andrewnc Abdelrahman350 Garvit9000c kzymgch Neoanarika alen1010 adamnemecek galv krasserm nealmcb petercerno Prahitha khanshehjad hieuza jlh2018 mvervuurt TripleTop
murphyk mjsML ashishpapanai Duane321 animesh-007 Nirzu97 Drishttii always-newbie161 nappaillav jdf22 shivaditya-meduri karalleyna gerdm andrewnc Abdelrahman350 Garvit9000c kzymgch Neoanarika alen1010 adamnemecek galv krasserm nealmcb petercerno Prahitha khanshehjad hieuza jlh2018 mvervuurt TripleTop
Comments
  • convert legacy matlab code to python

    convert legacy matlab code to python

    If you want to contribute a Python version of a figure, follow these steps:

    • Check the list of open issues for ones with a name like "Convert foo to Python". Such issues have the tag 'Figures'. Each issue has a link to the Matlab file that was used to generate the figure, and a figure number. Figure numbers refer to this version of the book: https://github.com/probml/pml-book/releases/tag/2021-03-08. Consult the pdf file to see what the figure should look like.

    • Follow these guidelines for how to contribute code.

    • Test your code works in Google colab, and make a pull request. Please include the generated image(s) in your PR, and add a tag which mentions the issue you are solving.

    • Here is an example of good PR.

    • If you are a student and want to be considered for the Google Summer of Code, please apply here after March 29th. You should have at least 2 PRs succesfully added to this repo before applying. Please follow the style guidelines mentioned above.

    opened by murphyk 25
  • convert pytorch d2l.ai demos to JAX

    convert pytorch d2l.ai demos to JAX

    In vol 1 of my book, I use several notebooks taken from the book Dive Into Deep Learning. These are written in pytorch and stored at https://github.com/probml/probml-notebooks/tree/main/notebooks-d2l. The task is to convert these notebooks into JAX/FLAX code. It's okay to keep using torch dataloaders, but you should replace torch.tensor with jax.np.array, and torch.nn with flax.linen.nn, etc. Be sure to replace idioms like np.random.seed(seed=1); torch.manual_seed(1) with proper JAX PRNGs.

    You should make a JAX version of each notebook, and open a PR for each one at https://github.com/probml/probml-notebooks/tree/main/notebooks-d2l. If the original notebook is called foo_torch.ipynb, please call yours foo_jax.ipynb.

    See this example for how to format your code and PR.

    Before you start translating a notebook, please check that it has not already been done! (I only want one translation per notebook :)

    GSOC 
    opened by murphyk 17
  • Accelerate workflow by including SMOKE_RUN

    Accelerate workflow by including SMOKE_RUN

    After adding D2L notebooks, workflow execution time has increased from 1 hour to 2 hours 14 minutes. Ideally, the workflow should be as fast as possible so that we can know the failing components quickly. One of the solutions for this is to enable an environment variable called SMOKE_RUN for notebooks containing epoch-wise training with a logic that if SMOKE_RUN is in the environment we run only 1-2 epochs else we run the maximum epochs as mentioned in the notebook.

    internal 
    opened by patel-zeel 15
  • mlpPriorsDemo2

    mlpPriorsDemo2

    Hello, this is a Python implementation for mlpPriorsDemo2. The figures are slightly different from the book because NumPy generates different random vectors than Matlab.

    opened by Abdelrahman350 14
  • figure out why ELBO does not improve with pymc3 ADVI demi

    figure out why ELBO does not improve with pymc3 ADVI demi

    The advi.hist (ELBO) should increase over time, but it does not seem to, even though the posterior looks sensible. Find out why. https://github.com/probml/probml-notebooks/blob/main/notebooks/beta_binom_approx_post_pymc.ipynb

    GSOC 
    opened by murphyk 13
  • Porting the complete book code to Python?

    Porting the complete book code to Python?

    Hello Kevin,

    I was wondering if there is a plan to port all of the code examples from the ML book to Python?

    If that's the case I'd love to help out :)

    opened by thvasilo 12
  • Implemented SNGP JAX Demo

    Implemented SNGP JAX Demo

    opened by nsanghi 11
  • implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM  using JSL

    implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM using JSL

    Implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM . In the "E step", use the Jax SSM library for forwards-filtering backwards-sampling. In the "M step", sample from the parameter posteriors assuming conjugate priors.

    Some details can be found in this paper A. Wills, T. B. Schön, F. Lindsten, and B. Ninness, “Estimation of Linear Systems using a Gibbs Sampler,” IFAC proc. vol., vol. 45, no. 16, pp. 203–208, Jul. 2012, doi: 10.3182/20120711-3-be-2027.00297. [Online]. Available: https://linkinghub.elsevier.com/retrieve/pii/S1474667015379520

    JSL 
    opened by murphyk 10
  • Missing superimport module for compare_results.ipynb

    Missing superimport module for compare_results.ipynb

    I encounter the following error when running compare_results.ipynb in the vae folder.

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    <ipython-input-2-d04a2cc14755> in <module>()
          5 import matplotlib.pyplot as plt
          6 import torchvision.transforms as transforms
    ----> 7 from download_celeba import celeba_dataloader
          8 from assembler import get_config, assembler
          9 from utils.plot import plot_reconstruction, plot_samples
    
    /content/download_celeba.py in <module>()
    ----> 1 import superimport
          2 
          3 from absl import app
          4 from absl import flags
          5 import torchvision.transforms as transforms
    

    I think this can be resolved by adding one line in the notebook to download superimport into the colab.

    opened by Neoanarika 10
  • Converted mixBerMnistEM to python

    Converted mixBerMnistEM to python

    mixBernoulliMnist

    Closes #174

    The code might take some time to load and this is because it is downloading the MNIST dataset from online and the delay in execution is solely due to this and not due to the inefficiency of the code.

    The values and the images will differ because the data is randomly chosen from the total set of images.

    I initially added +1 to all images in the training set and changed the Bernoulli function to adapt to this, but did not see any change in the execution, It was more convenient for me to use the binary image as is and use the implementation of Bernoulli distribution which is used for this mixture model.

    In this implementation, I did not find the optimal k because the optimal k=20 has already been found through trial and error in the MATLAB code and no graph implementation is found in the book.

    Implemented the changes suggested:

    1. Vectorized code and replaced iterating over the data points to vectorized versions
    2. replaced Bernoulli function with https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.bernoulli.html
    3. factored out the code that does parameter initialization and image plotting into subfunctions, to simplify main()
    4. changed the data source from open_ml to tensorflow.datasets
    opened by shivaditya-meduri 10
  • estimate mutual information for all pairs of WHO variables

    estimate mutual information for all pairs of WHO variables

    opened by murphyk 10
  • Figure 6.1 missing sub-figure c) showing a sequence logo.

    Figure 6.1 missing sub-figure c) showing a sequence logo.

    Figure 6.1 b) shows a graphic depiction of a position frequency matrix, but it is not a sequence logo because all column heights are equal. My guess is the original intent was to have a sub-figure 6.1 c) showing a sequence logo and compare that to the graphic in sub-figure 6.1 b) so the reader can see how much easier it is to spot conserved positions when the column heights are scaled to equal the information content. The text corresponding to figure 6.1 does mention heights scaled to information content (although "bar" height is used instead of "column" height.

    opened by paulhorton 0
  • tweak book 1 fog 7.6  gaussEvec.ipynb

    tweak book 1 fog 7.6 gaussEvec.ipynb

    To solve https://github.com/probml/pml-book/issues/440 Tweak https://colab.research.google.com/github/probml/pyprobml/blob/master/notebooks/book1/07/gaussEvec.ipynb The exponents should be lambda^{-1/2}. I tried changing the text but the figure no longer renders properly (u_1, u_2 axis broken)

    Screen Shot 2022-07-28 at 11 55 07 PM
    opened by murphyk 0
  • Make bnn_mnist_sgld_blackjax.ipynb to be able to run in colab

    Make bnn_mnist_sgld_blackjax.ipynb to be able to run in colab

    • currently, this notebook won't run in colab, due to requirement of high memory.
    • Mostly prediction loops taking much memory, we can make it batch prediction to consume less memory at a time
    opened by karm-patel 0
Releases(v0.1.0)
  • v0.1.0(May 5, 2022)

Owner
Probabilistic machine learning
Material to accompany the book "Machine Learning: A Probabilistic Perspective" (Software, Data, Exercises, Figures, etc)
Probabilistic machine learning
A high-level app and dashboarding solution for Python

Panel provides tools for easily composing widgets, plots, tables, and other viewable objects and controls into custom analysis tools, apps, and dashboards.

HoloViz 2.5k Jan 03, 2023
Extendable, adaptable rewrite of django.contrib.admin

django-admin2 One of the most useful parts of django.contrib.admin is the ability to configure various views that touch and alter data. django-admin2

Jazzband 1.2k Dec 29, 2022
Django Smuggler is a pluggable application for Django Web Framework that helps you to import/export fixtures via the automatically-generated administration interface.

Django Smuggler Django Smuggler is a pluggable application for Django Web Framework to easily dump/load fixtures via the automatically-generated admin

semente 373 Dec 26, 2022
Helpers to extend Django Admin with data from external service with minimal hacks

django-admin-data-from-external-service Helpers to extend Django Admin with data from external service with minimal hacks Live demo with sources on He

Evgeniy Tatarkin 7 Apr 27, 2022
xarray: N-D labeled arrays and datasets

xarray is an open source project and Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun!

Python for Data 2.8k Dec 29, 2022
A jazzy skin for the Django Admin-Interface (official repository).

Django Grappelli A jazzy skin for the Django admin interface. Grappelli is a grid-based alternative/extension to the Django administration interface.

Patrick Kranzlmueller 3.4k Dec 31, 2022
A minimalist GUI frontend for the youtube-dl. Takes up less than 4 KB.

📥 libre-DL A minimalist GUI wrapper for youtube-dl. Written in python. Total size less than 4 KB. Contributions welcome. You don't need youtube-dl pr

40 Sep 23, 2022
Material Design for Django

Django Material Material design for Django. Django-Material 1.7.x compatible with Django 1.11/2.0/2.1/2.2/3.0/3.1 Django-Material 1.6.x compatible wit

Viewflow 2.5k Jan 01, 2023
The script that able to find admin panels

admin_panel_finder The script will try to request possible admin panels by reading possible admin panels url then report as 200 YES or 404 NO usage: p

E-Pegasus 3 Mar 09, 2022
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Dec 31, 2022
Simple and extensible administrative interface framework for Flask

Flask-Admin The project was recently moved into its own organization. Please update your references to Flask-Admin 5.2k Dec 29, 2022

AdminFinderV1.5 - Hacking Website Admin Finder Defacer Script

Assalamualaikum Kembali Lagi bersama gua sang culun+nolep ini :v AdminFinder New

KOBUSTOR GHOST TEAM 2 Feb 15, 2022
django-admin fixture generator command

Mockango for short mockango is django fixture generator command which help you have data without pain for test development requirements pip install dj

Ilia Rastkhadiv 14 Oct 29, 2022
A python application for manipulating pandas data frames from the comfort of your web browser

A python application for manipulating pandas data frames from the comfort of your web browser. Data flows are represented as a Directed Acyclic Graph, and nodes can be ran individually as the user se

Schlerp 161 Jan 04, 2023
A new style for Django admin

Djamin Djamin a new and clean styles for Django admin based in Google projects styles. Quick start Install djamin: pip install -e git://github.com/her

Herson Leite 236 Dec 15, 2022
A Django admin theme using Twitter Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed apps.

django-admin-bootstrapped A Django admin theme using Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed ap

1.6k Dec 28, 2022
Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo

Django JET Modern template for Django admin interface with improved functionality Attention! NEW JET We are proud to announce completely new Jet. Plea

Geex Arts 3.4k Dec 29, 2022
Django app that enables staff to log in as other users using their own credentials.

Impostor Impostor is a Django application which allows staff members to login as a different user by using their own username and password. Login Logg

Andreu Vallbona Plazas 144 Dec 13, 2022
A user-friendly JSON editing form for Django admin

A user-friendly JSON editing form for Django admin

Bharat Chauhan 141 Dec 30, 2022
Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.

Xadmin Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap. Liv

差沙 4.7k Dec 31, 2022