Prediction by Bayesian linear regression

To modify your code to include additional predictors, you basically just have to add additional parameters/coefficients/slopes:

    # Slopes
    slope1 = pm.Normal('slope1', mu = 0, sd = 10)
    slope2 = pm.Normal('slope2', mu = 0, sd = 10)
    slope3 = pm.Normal('slope3', mu = 0, sd = 10)

Then use them:

    # Estimate of mean
    mean = (intercept + 
           (slope1 * dataset['x1']) +
           (slope2 * dataset['x2']) +
           (slope3 * dataset['x3']) )

There are more compact ways of specifying this, but it’s hard to go wrong with verbose and explicit.

2 Likes