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 ...

Get Bayesian Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.