Foundations to Frontier
Tests

The Bias–Variance Decomposition

Why do simple models miss and complex models flail? The bias–variance decomposition splits a learner's expected squared error into three parts: bias (systematic error from wrong assumptions), variance (sensitivity to the particular training sample), and irreducible noise. This topic derives the decomposition, shows how model complexity, regularization (ridge), neighbourhood size (k-NN) and data size move bias and variance, and explains why averaging many learners (bagging, random forests) reduces variance. In the research exercise you measure all three terms by Monte Carlo for polynomials, ridge and k-NN, verify k-NN's σ²/k variance law, and show that bagging halves the variance of an unstable learner.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Two ways to be wrong

Imagine many students each learning from a different set of practice problems.

  • Bias: if they all make the same mistake because their method is too simple, that’s bias. More practice won’t fix it.
  • Variance: if each student’s answer depends wildly on which problems they happened to practise, that’s variance. Averaging many students, or giving each more practice, helps.

On top of both, the questions themselves contain some randomness (noise) that nobody can predict.

Bias and variance: 30 learners, 30 training sets
average bias² 0.0038 · average variance 0.0319 · noise σ² 0.090 · expected test error ≈ 0.126
Dashed: the truth. Orange: the average learner. Blue: individual learners trained on different samples. Low degrees are stiff: they all agree (low variance) but miss the curve (high bias). High degrees wiggle to chase each sample's noise: right on average (low bias) but wildly different from sample to sample (high variance). More data tames variance; nothing removes the noise floor σ². Lines are clipped at ±2.2.
Why engineers care

Choosing model size, regularization strength or how many neighbours to use is always a bias–variance trade-off. With small datasets, typical in robotics and space science (few flights, rare events), variance dominates, so simpler models, regularization and ensembles matter. Ensembles such as random forests and deep ensembles also give uncertainty estimates.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A model that's systematically off in the same way, whatever the data, has high…
  2. 2. A model whose predictions change a lot with each new training set has high…
  3. 3. Can more data reduce the irreducible noise?

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

The decomposition

Let y=f(x)+εy = f(x) + \varepsilon with Eε=0\mathbb E\varepsilon = 0 and Var⁡ε=σ2\operatorname{Var}\varepsilon = \sigma^2. Let f^D\hat f_D be trained on a random dataset D. At a point x,

ED,ε[(f^D(x)−y)2]=(EDf^D(x)−f(x))2⏟bias2+Var⁡Df^D(x)⏟variance+σ2⏟noise.\mathbb E_{D,\varepsilon}\big[(\hat f_D(x) - y)^2\big] = \underbrace{\big(\mathbb E_D\hat f_D(x) - f(x)\big)^2}_{\text{bias}^2} + \underbrace{\operatorname{Var}_D\hat f_D(x)}_{\text{variance}} + \underbrace{\sigma^2}_{\text{noise}}.

Bias is about the average learner. Variance is about how learners trained on different samples disagree.

What moves each term

  • More complexity (higher degree, smaller k, deeper trees) lowers bias and raises variance.
  • More data lowers variance; bias is unchanged.
  • Regularization (ridge, early stopping) raises bias a little and lowers variance a lot.
  • Averaging independent-ish learners lowers variance and leaves bias unchanged.
📝 Quick check (Level 1)
0/3 answered
  1. 1. If bias² = 0.01, variance = 0.02 and σ² = 0.09, the expected error is…
  2. 2. More training data mainly reduces…
  3. 3. Increasing a ridge penalty typically…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

k-nearest neighbours

The prediction averages k noisy labels. If the neighbours are close enough that f barely changes, its variance is σ2/k\sigma^2/k. Larger k averages over a wider neighbourhood, so bias grows with the curvature of f. The best k balances the two; it grows with n, and k-NN is consistent if k→∞k\to\infty and k/n→0k/n\to0.

Averaging learners

For M predictors, each with variance σ² and pairwise correlation ρ, the average has variance

ρσ2+1−ρMσ2.\rho\sigma^2 + \frac{1 - \rho}M\sigma^2.

Averaging kills the uncorrelated part but not the shared part. Bagging (Breiman, 1996) trains on bootstrap resamples to make learners differ. Random forests also subsample features to cut ρ further (Breiman, 2001).

Beyond squared loss

For 0-1 loss the decomposition isn’t additive, and bias and variance can interact (Domingos, 2000). Modern over-parameterized networks also break the classic U-shaped curve (double descent, B4). The decomposition is still the right first lens.

🐍 Exercise 1: measuring bias and variance
Fit polynomials (and ridge-regularized polynomials) to many independent training sets. Measure bias², variance and noise at a point by Monte Carlo, check that they add up to the expected squared error, and find the complexity and penalty that minimize their sum.
📝 Quick check (Level 2)
0/3 answered
  1. 1. k-NN variance (nearby neighbours, noise σ):
  2. 2. Averaging infinitely many learners with correlation ρ leaves variance…
  3. 3. Random forests reduce correlation between trees by…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proof of the decomposition

Write fˉ=EDf^D(x)\bar f = \mathbb E_D\hat f_D(x). Then f^D−y=(f^D−fˉ)+(fˉ−f)−ε\hat f_D - y = (\hat f_D - \bar f) + (\bar f - f) - \varepsilon. Square and take expectations. The cross terms vanish because ED[f^D−fˉ]=0\mathbb E_D[\hat f_D - \bar f] = 0, ε has mean 0, and ε is independent of D. The result is Var⁡f^D+(fˉ−f)2+σ2\operatorname{Var}\hat f_D + (\bar f - f)^2 + \sigma^2. ∎

Variance of an average

Var⁡(1M∑Zi)=1M2(Mσ2+M(M−1)ρσ2)=ρσ2+1−ρMσ2\operatorname{Var}\big(\tfrac1M\sum Z_i\big) = \tfrac1{M^2}\big(M\sigma^2 + M(M - 1)\rho\sigma^2\big) = \rho\sigma^2 + \tfrac{1 - \rho}M\sigma^2. ∎

k-NN variance

With the neighbours’ inputs fixed, the prediction is 1k∑(f(x(i))+εi)\tfrac1k\sum(f(x_{(i)}) + \varepsilon_i), which has variance σ2/k\sigma^2/k conditionally. Randomness in which points are neighbours adds a little more. ∎

Exercise 3.1: a forest’s variance

25 trees with variance 0.2 and correlation 0.6: 0.6⋅0.2+0.4⋅0.2/25=0.12320.6\cdot0.2 + 0.4\cdot0.2/25 = 0.1232. Correlation, not the number of trees, sets the floor.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The decomposition's cross terms vanish because…
  2. 2. Variance of 25 averaged learners (σ² = 0.2, ρ = 0.6):
  3. 3. k-NN with k → ∞ but k/n → 0 is…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Bias and variance, measured

Polynomials. At x = 0.25, with 30 points per training set and σ = 0.3, over 3000 training sets:

model bias² variance noise total
degree 1 0.2646 0.0193 0.090 0.374
degree 3 0.0001 0.0112 0.090 0.099
degree 9 0.0000 0.0369 0.090 0.129

The three terms add up to the measured expected error. (These are the browser’s numbers; the degree-9 fit amplifies rounding, so results differ slightly by platform: desktop CPython gives variance 0.0367.)

Ridge on degree 9: λ = 10⁻⁸, 10⁻⁴ and 10⁻³ give bias² of 0.0000, 0.0010 and 0.0101 and variance of 0.0209, 0.0121 and 0.0101. The middle penalty has the lowest total.

k-NN (n = 200): the variance at k = 1, 5 and 20 is 0.0900, 0.0187 and 0.0042, matching σ²/k = 0.090, 0.018 and 0.0045. At k = 80, bias² jumps to 0.063.

Bagging 50 bootstrap 1-NN predictors halves the variance (0.092 → 0.042) without adding noticeable bias.

🐍 Exercise 2 (research): k-NN and bagging
Measure k-NN's bias² and variance at a point for several k and compare the variance with σ²/k. Then bag 1-NN over bootstrap resamples and measure how much variance falls.

Bias and variance in AI, robotics and aerospace

  • Model selection: cross-validation estimates the total; learning curves diagnose bias (both errors high) versus variance (big train–test gap).
  • Ensembles: random forests and gradient boosting for tabular sensor data; deep ensembles for uncertainty in perception.
  • Small-data science: flight-test and mission data are scarce, so strong priors and regularization trade a little bias for a lot of variance.
  • Estimation theory: the Cramér–Rao bound (a12-5) and James–Stein shrinkage are bias–variance results in disguise.

References

  1. S. Geman, E. Bienenstock, R. Doursat (1992). “Neural networks and the bias/variance dilemma.” Neural Computation, 4.
  2. T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, 2nd ed. Springer.
  3. L. Breiman (1996). “Bagging predictors.” Machine Learning, 24.
  4. L. Breiman (2001). “Random forests.” Machine Learning, 45.
  5. P. Domingos (2000). “A unified bias-variance decomposition.” ICML.