Skip to content

BayesianLinearRegression

Bayesian linear regression.

An advantage of Bayesian linear regression over standard linear regression is that features do not have to scaled beforehand. Another attractive property is that this flavor of linear regression is somewhat insensitive to its hyperparameters. Finally, this model can output instead a predictive distribution rather than just a point estimate.

The downside is that the learning step runs in O(n^2) time, whereas the learning step of standard linear regression takes O(n) time.

Parameters

  • alpha – defaults to 1

    Prior parameter.

  • beta – defaults to 1

    Noise parameter.

Examples

>>> from river import datasets
>>> from river import evaluate
>>> from river import linear_model
>>> from river import metrics

>>> dataset = datasets.TrumpApproval()
>>> model = linear_model.BayesianLinearRegression()
>>> metric = metrics.MAE()

>>> evaluate.progressive_val_score(dataset, model, metric).get()
0.5818

>>> x, _ = next(iter(dataset))
>>> model.predict_one(x)
43.61

>>> model.predict_one(x, as_dist=True)
𝒩(μ=43.616, σ=1.003)

Methods

learn_one

Fits to a set of features x and a real-valued target y.

Parameters

  • x (dict)
  • y (numbers.Number)

Returns

Regressor: self

predict_one

Predict the output of features x.

Parameters

  • x (dict)
  • as_dist – defaults to False

Returns

Number: The prediction.

References