Skip to content

About

Code for a tutorial on Bayesian Statistics by Allen Downey.

Topics

Resources

Stars

358 stars

Watchers

17 watching

Forks

Repository files navigation

Bayesian Statistics Made Simple

tests

Allen Downey

Bayesian statistical methods are becoming more common, but there are not many resources to help beginners get started. People who know Python can use their programming skills to get a head start.

In this tutorial, I introduce Bayesian methods using grid algorithms, which help develop understanding and prepare for MCMC, which is a powerful algorithm for real-world problems.

It is based on my book, Think Bayes, and my blog, Probably Overthinking It.

This is one of my workshops and tutorials.

Level: beginner. You should be comfortable with basic Python; some experience with NumPy and pandas helps. You don't need any background in statistics.

Length: about 90 minutes.

Outline

  1. The cookie problem: Bayes's theorem as a table of priors, likelihoods and posteriors, using a pandas Series; then the 101 Bowls problem, which leads to distributions of quantities.
  2. The Euro problem: estimating the probability that a coin lands heads; uniform and triangle priors, the posterior mean, and credible intervals.
  3. The Bayesian bandit: updating beliefs about several slot machines as you play them, and using those beliefs to decide which one to play next (Thompson sampling).

Each notebook comes in two versions: one with blanks for the exercises, and one with solutions.

Notebook Exercises Solutions
1. The cookie problem Run on Colab Run on Colab
2. The Euro problem Run on Colab Run on Colab
3. The Bayesian bandit Run on Colab Run on Colab

Slides for this tutorial are here.

Recordings

I presented this tutorial at PyCon US every year from 2012 to 2016 and at SciPy 2019. The code in the videos is not the current version; the tag after each link is the version of the code that goes with it.

Running the notebooks

The easiest way to run the notebooks is on Colab: click one of the links above. You need a Google account, but you don't have to install anything.

To run them on your own computer, you need Python 3 with Jupyter, NumPy, pandas, SciPy, Matplotlib, and Seaborn. You can download the code in this zip file, or clone the repository:

git clone https://github.com/AllenDowney/BayesMadeSimple
cd BayesMadeSimple

Then install the packages with pip:

pip install -r requirements.txt

Or, if you use conda or mamba, create an environment:

mamba env create -f environment.yml
mamba activate BayesMadeSimple

Then run jupyter lab and open 01_cookie.ipynb.

Next steps

To go further, read Think Bayes, which is free online, or see my other workshops, including ones on Bayesian decision analysis and on PyMC.

License

The code is available under the MIT License. The text is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

About

Code for a tutorial on Bayesian Statistics by Allen Downey.

Topics

Resources

Stars

358 stars

Watchers

17 watching

Forks

Releases

Packages

Contributors

Languages