Book Image

Bayesian Analysis with Python

Book Image

Bayesian Analysis with Python

Overview of this book

The purpose of this book is to teach the main concepts of Bayesian data analysis. We will learn how to effectively use PyMC3, a Python library for probabilistic programming, to perform Bayesian parameter estimation, to check models and validate them. This book begins presenting the key concepts of the Bayesian framework and the main advantages of this approach from a practical point of view. Moving on, we will explore the power and flexibility of generalized linear models and how to adapt them to a wide array of problems, including regression and classification. We will also look into mixture models and clustering data, and we will finish with advanced topics like non-parametrics models and Gaussian processes. With the help of Python and PyMC3 you will learn to implement, check and expand Bayesian models to solve data analysis problems.
Table of Contents (15 chapters)
Bayesian Analysis with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Exercises


  1. This exercise is about regularization priors. In the code that generates the data, change order=2 to another value, such as, order=5. Then fit model_p and plot the resulting curve. Repeat but now using a prior for beta with sd=100 instead of sd=1 and plot the resulting curve. How are both curves different? Try it also with sd=np.array([10, 0.1, 0.1, 0.1, 0.1]).

  2. Repeat the previous exercise but increase the amount of data to 500 data points.

  3. Fit a cubic model (order 3), compute WAIC and LOO, plot the results, and compare them with the linear and quadratic models.

  4. Use pm.sample_ppc() to re-run the PPC example, but this time plot the values of y instead of the values of the mean.

  5. Read and run the posterior predictive example from PyMC3's documentation at https://pymc-devs.github.io/pymc3/notebooks/posterior_predictive.html. Pay special attention to the use of the Theano shared variables.

  6. Compute the Bayes factor for the coin problem using a uniform prior beta(1, 1) and priors such as beta...