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

The GLM module


Linear models are widely used in statistics and machine learning. For that reason, PyMC3 includes a module named glm, which stand for generalized linear model, the name will become clear in the next chapter. The glm module simplifies writing linear models. For example, a simple linear regression will be:

with Model() as model:
    glm.glm('y ~ x', data)
    trace = sample(2000)

The second line of the preceding code takes care of adding default flat priors for the intercept and for the slope and a Gaussian likelihood. These are OK if you just want to run a default linear regression. Note that the MAP of this model will be essentially equivalent to the one obtained using the (frequentist) ordinary least square method. If you need to, you can also use the glm module and change priors and likelihoods. If you are not familiar with R's syntax, 'y ~ x' specifies that we have an output variable that we want to estimate as a linear function of . The glm module also includes a function...