Skip to content

Guide · Open source

How to use Bayesian Methods for Hackers: clone, run notebooks, learn PyMC

Updated · written with AI from the project's own documentation and checked against our catalogue data

Bayesian Methods for Hackers is a free, open book of Jupyter notebooks that teaches Bayesian inference through running and changing Python code, with less emphasis on probability theory. It suits programmers who know some Python and people who find traditional statistics texts too abstract. By the end of this guide you will know how to get the notebooks onto your machine, which chapters to read first, and what the book does and does not cover.

Bayesian Methods for HackersCamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers · ★ 28.2k · MIT

Quick start

  1. 1Check prerequisites. Make sure Python and Jupyter Notebook are installed on your machine.
  2. 2Clone the repository. Run the git clone command from this guide in a terminal to download the notebooks.
  3. 3Open Jupyter. Start Jupyter Notebook from the cloned folder and open a chapter.
  4. 4Pick a PyMC version. Choose the PyMC2 or PyMC3 notebook for your chapter, matching the library you have installed.
  5. 5Run and modify the code. Execute the cells in order, then change a prior or a parameter and rerun to see the effect.
  6. 6Consult the official docs. Use the official PyMC documentation for the current API, since the book is not a reference manual.

What is Bayesian Methods for Hackers?

The project is an introduction to Bayesian inference written from a computational, understanding-first point of view, with mathematics second. The README states that the book is aimed at readers with less mathematical background who care more about practice than proofs.

The examples use the PyMC probabilistic programming library, along with NumPy, SciPy and Matplotlib. The README says the examples rely only on these packages so that the user is not limited.

Install the notebooks on your computer

The project is installed by cloning the repository. The prerequisites listed for the project are Python and Jupyter Notebook. Run the clone command below in a terminal, then open the notebooks in Jupyter.

The README notes that the chapters can be read online through nbviewer, which is read-only. To run and modify the code, clone the repository instead.

  • Prerequisites: Python and Jupyter Notebook
  • PyMC is a dependency; the README says PyMC depends on NumPy and optionally SciPy
git clone https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers.git

Choose between the PyMC2 and PyMC3 notebooks

The notebooks are organized into two sets: PyMC2 and PyMC3. Each chapter exists in both versions, with file names that end in the matching version, such as Ch1_Introduction_PyMC2.ipynb and Ch1_Introduction_PyMC3.ipynb.

Pick the set that matches the PyMC version you plan to use. The README points to the official PyMC documentation for the current API, so use that resource when you need reference details.

Work through the chapters in order

The book starts with a Prologue on why we do Bayesian inference. Chapter 1 introduces the philosophy and practice of Bayesian methods and asks what probabilistic programming is. Chapter 2 shows how to build Bayesian models in PyMC.

Chapter 3 covers how MCMC works and the diagnostic tools used with it. Chapter 4 covers the Law of Large Numbers, and Chapter 5 introduces loss functions. Chapter 6 is about priors and is described in the README as probably the most important chapter.

  • Prologue: why we do it
  • Chapter 1: Introduction to Bayesian Methods (example: inferring changes in text message rates)
  • Chapter 2: A little more on PyMC (examples: frequency of cheating students, Challenger space-shuttle disaster probabilities)
  • Chapter 3: Opening the Black Box of MCMC (example: Bayesian clustering with mixture models)
  • Chapter 4: The Greatest Theorem Never Told (examples: a Kaggle dataset, sorting Reddit comments)
  • Chapter 5: Would you rather lose an arm or a leg? (examples: The Price is Right's Showdown, financial predictions)
  • Chapter 6: Getting our prior-ities straight (examples: multi-armed bandits, using expert priors)

Use the notebooks to practise priors and MCMC

Because the notebooks are meant to be run and edited, the most effective way to learn is to change one thing at a time, rerun the cell, and compare the output. The README highlights priors and MCMC as core topics, so spend time on Chapters 3 and 6.

If you already know the basics, the book is also a practical set of examples you can adapt to your own data.

  • Change a prior and check how the posterior moves
  • Read the MCMC chapter alongside the code that runs it
  • Note whether a chapter is in the PyMC2 or PyMC3 folder before copying code

What people use it for

  • Inferring whether the rate of text messages changed over time
  • Estimating the frequency of cheating students while accounting for liars
  • Building a Bayesian mixture model for clustering
  • Comparing multi-armed bandit strategies with a Bayesian approach
  • Learning how to set priors using expert opinion

Frequently asked questions

Is Bayesian Methods for Hackers free?

The repository is released under the MIT licence, as listed on the project page. A printed version by Addison-Wesley is also sold, which the README says adds a chapter on Bayesian A/B testing and updated examples.

What do I need to run the notebooks?

The listed prerequisites are Python and Jupyter Notebook. The examples use PyMC, NumPy, SciPy and Matplotlib, and the README says PyMC depends on NumPy and optionally SciPy.

How do I install Bayesian Methods for Hackers?

Clone the repository with git clone from the GitHub URL in the README, then open the notebooks in Jupyter. The project is installed by cloning and running the notebooks rather than through a package installer.

Do I need strong maths to follow the book?

No. The README says the book prioritizes computation and understanding over mathematics and is aimed at readers with less mathematical background. Readers who want rigorous derivations should use other texts.

Should I use PyMC2 or PyMC3 notebooks?

Use the version that matches the PyMC library you install, since the notebooks are organized by PyMC2 and PyMC3. The README points to the official PyMC documentation for the current API.

How does it compare to the PyMC documentation?

The README says the official documentation assumes prior knowledge of Bayesian inference and probabilistic programming. This book is intended as a hands-on introduction, while the official docs are the reference for the API.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Choose this if you know some Python and want to learn Bayesian methods by running and editing code, or if you want a hands-on introduction to PyMC. Pick a different resource if you need rigorous mathematical derivations or a reference manual for the current PyMC API.

Install options & downloads