Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Being honest about what you don’t know
With only two points, many lines fit almost equally well. Instead of picking one and pretending it’s certain, Bayesian regression keeps all the plausible lines, weighted by how believable they are. Where the data are, the lines agree; far away, they fan out. The spread is the model saying “I’m not sure here”. Each new point narrows the fan.
A prediction without an error bar can’t be used in a safety margin or a risk budget. Bayesian regression gives calibrated uncertainty for small datasets (a few test flights, a handful of material samples) and updates it cheaply as each new measurement arrives, which is the same algebra as the Kalman filter.
- 1. Bayesian regression keeps…
- 2. In the demo, uncertainty is largest…
- 3. Adding data makes the posterior…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Updating a slope by hand
Model: y = w·x + noise, with noise precision β = 1 (variance 1) and prior w ~ N(0, 1/α) with α = 1. Data: (1, 2) and (2, 4).
- Posterior precision: α + β·Σx² = 1 + 1·(1 + 4) = 6, so the posterior variance is 1/6.
- Posterior mean: β·Σxy / precision = (2 + 8)/6 = 1.67. Least squares would give 10/5 = 2; the prior pulls it toward 0, exactly like ridge with λ = α/β = 1.
- Predictive variance at x: 1/β + x²/6. At x = 0 it is just the noise, 1. At x = 3 it is 1 + 9/6 = 2.5.
The steps in plain English:
- Write down a prior: how large the coefficients plausibly are.
- Combine it with the data. For Gaussians this is a matrix formula that gives the posterior mean and covariance.
- Predict with the posterior mean, and add the noise variance to the parameter uncertainty in that direction.
- Optionally, learn the prior and noise strength from the data (empirical Bayes).
- 1. The posterior mean with a Gaussian prior equals…
- 2. Posterior precision adds…
- 3. The predictive variance never falls below…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.The equations
Model: y = Φw + ε, with ε ~ N(0, β⁻¹I) and prior w ~ N(0, α⁻¹I). Φ holds the features or basis functions.
Posterior: w | y ~ N(m, S), with
- S⁻¹ = αI + βΦᵀΦ;
- m = βSΦᵀy.
Predictive at a new φ: mean φᵀm and variance 1/β + φᵀSφ.
Evidence (marginal likelihood):
log p(y | α, β) = (M/2)log α + (N/2)log β − E(m) − ½log|A| − (N/2)log 2π,
where A = S⁻¹ and E(m) = (β/2)‖y − Φm‖² + (α/2)‖m‖².
Empirical Bayes maximises the evidence by MacKay’s fixed-point updates:
- γ = Σλᵢ/(α + λᵢ), where λᵢ are the eigenvalues of βΦᵀΦ;
- α = γ/‖m‖²;
- β = (N − γ)/‖y − Φm‖².
Here γ counts the “well-determined” parameters.
Sequential learning: yesterday’s posterior is today’s prior. Updating one point at a time gives exactly the batch answer.
from sklearn.linear_model import BayesianRidge, ARDRegression
model = BayesianRidge(compute_score=True).fit(X, y) # empirical Bayes for α and β
mean, std = model.predict(X_new, return_std=True)
print(model.alpha_, model.lambda_) # sklearn: alpha_ = noise precision β, lambda_ = weight precision αHyperparameters: α and β (learned by evidence or set from domain knowledge), and the choice of basis. Use it when data are scarce, uncertainty matters, or data arrive sequentially. Beware that uncertainty is only as good as the model: a wrong basis gives confident wrong answers.
- 1. S⁻¹ = αI + βΦᵀΦ is the posterior…
- 2. γ in empirical Bayes counts…
- 3. In sklearn's BayesianRidge, alpha_ is…
Level 3: Advanced
★★★★☆ Advanced⏱ 35 minGraduate level, with full derivations and proofs.Derivation and connections
Derivation. The log posterior is −(β/2)‖y − Φw‖² − (α/2)‖w‖² + const, a quadratic in w. Completing the square:
- the quadratic term wᵀ(βΦᵀΦ + αI)w gives the precision S⁻¹;
- the linear term βwᵀΦᵀy gives m = βSΦᵀy.
The MAP and posterior mean coincide (Gaussian), and equal ridge with λ = α/β.
Predictive distribution. Integrating p(y* | w) against the posterior gives a Gaussian with variance 1/β + φᵀSφ. The second term vanishes as N → ∞ only where data are plentiful.
Evidence and Occam’s razor. The evidence balances fit, E(m), against complexity: ½log|A| and the log α, log β terms penalise models whose parameters must be finely tuned. Maximising it chooses regularisation without a validation set.
Connections:
- Kalman filter: sequential Bayesian regression with a static state.
- Gaussian processes (A4.4.6): Bayesian regression with infinitely many basis functions; the kernel is k(x, x′) = φ(x)ᵀφ(x′)/α.
- ARD (D1.10): one α per weight.
- Bayesian ridge vs ridge: identical point predictions for the same λ, plus uncertainty and automatic λ.
Limitations:
- Gaussian noise and linearity in parameters are assumed.
- Uncertainty ignores model misspecification.
- Unknown σ² can instead be handled with a normal–inverse-gamma prior, which gives Student-t predictives.
Interview questions.
- Why do Bayesian error bars widen away from the data? φᵀSφ is small only in directions that the data constrain.
- How does Bayesian ridge choose λ without CV? By maximising the marginal likelihood (evidence).
- 1. Bayesian regression with infinitely many basis functions becomes…
- 2. Sequential Bayesian updates are the static case of…
- 3. Bayesian intervals can still fail when…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Are the error bars honest?
History. Bayes and Laplace set out the posterior idea in the 18th century. Lindley and Smith (1972) gave hierarchical linear models. MacKay’s evidence framework (1992) brought empirical Bayes to neural networks and basis-function models. Tipping (2001) and Bishop’s Pattern Recognition and Machine Learning (2006) popularised these models in ML.
Exercise 1.
- The posterior mean equals ridge with λ = α/β, and one-point-at-a-time updating reproduces the batch posterior exactly.
- Empirical Bayes recovers the noise level (σ̂ = 0.194, true 0.2) with γ = 1.97 well-determined parameters out of 2.
- The evidence peaks at the empirical-Bayes α.
- The predictive SD grows from 0.203 at x = 0 to 0.264 at x = 3.
Exercise 2: coverage of 90% prediction intervals (15 points on [0, 1], noise σ = 0.25, 400 datasets):
| Setting | Interval | Coverage inside [0, 1] | Coverage outside [1, 1.3] | Mean width outside |
|---|---|---|---|---|
| well specified (cubic truth, cubic basis) | plug-in ±1.645σ̂ | 0.876 | 0.726 | 0.89 |
| Bayesian predictive | 0.877 | 0.897 | 1.42 | |
| misspecified (sine, 6 Gaussian bumps) | plug-in | 0.856 | 0.176 | 0.97 |
| Bayesian predictive | 0.864 | 0.271 | 1.39 |
- When the model is right, Bayesian intervals keep their promise even when extrapolating (0.897 against the nominal 0.90). They do it by widening by 60% outside the data, where plug-in intervals that ignore parameter uncertainty cover only 73%.
- Inside the range, both are slightly short (0.86–0.88) because σ̂ is estimated from only 15 points.
- When the model is wrong, the bumps decay to a constant beyond x = 1 while the truth keeps going, and both intervals fail badly (18–27%).
Bayesian uncertainty covers parameter uncertainty within the model, not doubt about the model itself.
Bayesian regression in AI, robotics and aerospace
- Online parameter estimation: recursive Bayesian least squares for vehicle mass, drag or battery parameters.
- Small-data calibration: sensor calibration with uncertainty from a few reference points.
- Bayesian optimisation and surrogates: Bayesian linear models on learned features (neural-linear models).
- Space-weather and orbit models: regression with uncertainty for decision-making under risk.
References
- D. V. Lindley, A. F. M. Smith (1972). “Bayes estimates for the linear model.” JRSS B 34(1).
- D. J. C. MacKay (1992). “Bayesian interpolation.” Neural Computation 4(3).
- C. M. Bishop (2006). Pattern Recognition and Machine Learning, chapter 3. Springer.
- M. E. Tipping (2001). “Sparse Bayesian learning and the relevance vector machine.” JMLR 1.
- A. Gelman et al. (2013). Bayesian Data Analysis, 3rd ed., chapter 14. CRC Press.