Decompose Prediction Error into Bias and Variance
Statistics & ExperimentsModel answerLast updated
Derive the bias-variance decomposition of MSE from first principles and apply it to diagnose a concrete model comparison scenario.
Setting
A team is building a model to predict daily energy consumption (in kWh) for residential buildings. Two candidate models are evaluated on the same held-out test set:
| Model | Avg. Squared Error on Test Set | Notes |
|---|---|---|
| A | 42 | Simple linear regression, 3 features |
| B | 38 | Degree-5 polynomial regression, 20 features |
A teammate argues: "Model B has lower test error, so we should always prefer it."
A senior colleague pushes back: "That single number doesn't tell the whole story."
What You Are Expected To Do
-
Derive the bias-variance decomposition of the expected mean squared error (MSE) of a predictor from first principles. Define every term clearly.
-
Explain what each component (bias, variance, irreducible noise) represents intuitively, and sketch how they each change as model complexity increases.
-
Identify at least two concrete scenarios in which Model B's lower test-set MSE would not justify choosing it over Model A.
-
Propose a practical diagnostic procedure — using tools available to a working data scientist — to estimate whether a given model is suffering more from high bias or high variance.
-
Answer: if you could only run one additional experiment to decide between the two models, what would it be and why?
Hints
Hint 1
Start the derivation by adding and subtracting E[f̂(x)] inside the squared error term, then expand — this is the key algebraic trick.
Hint 2
For the scenarios where lower test error is misleading, think about dataset size, distribution shift, and the cost of complexity in production.
Hint 3
The learning curve (training error vs. validation error as a function of training set size) is one of the most informative single diagnostics for bias vs. variance.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Derivation of the Bias-Variance Decomposition
Let the true relationship be:
y = f(x) + ε, where ε ~ (0, σ²) [irreducible noise, independent of x]
Let f̂(x) be our learned predictor, trained on a dataset D drawn from the data-generating process. We want to decompose the expected squared error at a fixed point x, averaging over both ε and the randomness in D:
E[(y - f̂(x))²]
Step 1 — Add and subtract the expected prediction:
= E[(y - E[f̂(x)] + E[f̂(x)] - f̂(x))²]
Let A = y - E[f̂(x)] and B = E[f̂(x)] - f̂(x). Expand:
= E[A²] + 2·E[A]·E[B] + E[B²]
Since ε is independent of f̂(x), E[A·B] = 0 (the cross term vanishes).
Step 2 — Expand each piece:
E[A²] = E[(y - E[f̂(x)])²]
= E[(f(x) + ε - E[f̂(x)])²]
= (f(x) - E[f̂(x)])² + σ²
= Bias²[f̂(x)] + σ²
E[B²] = E[(E[f̂(x)] - f̂(x))²] = Var[f̂(x)]
Final decomposition:
E[(y - f̂(x))²] = Bias²[f̂(x)] + Var[f̂(x)] + σ²
Where:
- Bias = E[f̂(x)] - f(x): systematic error; how far the average prediction is from truth.
- Variance = E[(f̂(x) - E[f̂(x)])²]: sensitivity to the training sample; how much predictions fluctuate across datasets.
- σ²: irreducible noise inherent to the problem — cannot be reduced by any model.
2. Intuition and Complexity Curves
| Component | Low-complexity model | High-complexity model |
|---|---|---|
| Bias | High (underfits the signal) | Low (can capture the true f) |
| Variance | Low (stable across samples) | High (overfits noise) |
| σ² | Constant | Constant |
As complexity increases, bias decreases monotonically but variance increases. Total MSE is U-shaped; the optimal model sits at the minimum. A degree-5 polynomial with 20 features can memorize noise, driving up variance even while bias falls.
3. Two Scenarios Where Lower Test MSE Does Not Justify Choosing Model B
Scenario 1 — Small test set, high variance in the estimate itself.
If the test set contains, say, 200 samples, the standard error of an MSE estimate is roughly σ²_MSE / √n. A difference of 42 vs. 38 may not be statistically significant. Model B's apparent gain could be noise. A proper confidence interval or paired t-test on per-sample squared errors would reveal this.
Scenario 2 — Distribution shift in production.
A high-variance model that has overfit the training distribution will degrade disproportionately when production data drifts (e.g., a new building type, a seasonal regime not seen during training). Model A's stronger inductive bias (simplicity) acts as regularization against distributional extrapolation, potentially yielding lower real-world error even if test-set numbers favor B.
(Additional valid scenarios: Model B is too expensive to serve at inference latency requirements; interpretability constraints; training data contains leakage that inflates B's apparent advantage.)
4. Practical Diagnostic: High Bias vs. High Variance
Primary tool — learning curves.
Plot training MSE and validation MSE as a function of training set size N.
- High bias signature: Both curves converge to a high error plateau. Adding more data does not help much because the model family cannot represent the true function.
- High variance signature: Training error is low but validation error is substantially higher (large gap). The gap narrows as N grows because more data reduces variance.
Supporting checks:
- K-fold cross-validation spread: high standard deviation across folds signals high variance.
- Regularization sweep: if adding L2 regularization to Model B reduces validation error, variance was the dominant problem.
- Feature ablation / simpler baseline comparison: if a model with fewer features matches or beats Model B, complexity is not buying anything.
5. One Additional Experiment
Run a repeated k-fold cross-validation (e.g., 10×5-fold) and compare the full distribution of per-fold validation errors for both models.
Why this is the single most informative experiment:
- It gives a statistically grounded comparison — you can apply a paired test (Wilcoxon signed-rank or corrected resampled t-test) to assess whether the 4-unit difference is reliable.
- It exposes variance directly: if Model B's per-fold errors have high spread (e.g., range 20–60) while Model A's are stable (range 38–46), Model B's lower mean is misleading — it is a high-variance estimator.
- It uses all available data, unlike a single train/test split, giving a better estimate of generalization error at the actual training set size.
Common Mistakes to Avoid
- Forgetting σ²: candidates often write Bias² + Variance and omit that irreducible noise sets a floor no model can beat.
- Confusing bias of the model with bias of the estimator: the bias in the decomposition is about the model's systematic error on the true function, not statistical estimator bias in a frequentist sense (though they are analogous).
- Treating one test-set number as conclusive: in practice, a single point estimate of test error has its own variance; always ask about confidence intervals and whether the difference is meaningful.
- Assuming high complexity always means high variance: with sufficient regularization (dropout, ridge, early stopping), a complex model can have low variance. Complexity and variance are not identical.