Bias-Variance Tradeoff
Separate systematic error from sensitivity to the training sample. Read an error decomposition without assuming every model follows a U-shaped curve.
Jump to a section
Why this matters
A model can fail because its assumptions are too restrictive or because its fit changes too much with the training sample. Bias describes systematic error; variance describes sensitivity to the sampled data.
For squared error, the expected prediction error separates into bias squared, variance, and irreducible noise under the usual assumptions. The familiar U-shaped curve is a useful illustration, not a universal rule for every model.
Build the mental model
The dartboard analogy: bias is how far your cluster of shots sits from the bullseye; variance is how spread out the shots are. Four regimes:
- Low bias, low variance: tight cluster on target (the goal).
- High bias, low variance: tight cluster, wrong spot (underfit).
- Low bias, high variance: centered on average but scattered (overfit).
- High bias, high variance: scattered and off-target (worst case).
Read the illustrative decomposition
Bias falls while variance rises in this constructed squared-error example.
Exact inputs and equations appear with the figure.
Preparing the scientific figure…
Illustrative analytic curves, not measurements. A U-shaped complexity curve is not universal.
Authored analytic exampleExperiment with related Studio inputs
Notice where the falling bias term and rising variance term give the lowest total error.
Illustrative curves, not fitted measurements. Real models can show different behavior, including double descent.
Inspect the related Studio values
x,y,series 1,4,Bias squared 1,0.035,Variance 1,0.3,Noise 1,4.335,Total 2,2,Bias squared 2,0.14,Variance 2,0.3,Noise 2,2.44,Total 3,1.3333333333333333,Bias squared 3,0.31500000000000006,Variance 3,0.3,Noise 3,1.9483333333333335,Total 4,1,Bias squared 4,0.56,Variance 4,0.3,Noise 4,1.86,Total 5,0.8,Bias squared 5,0.8750000000000001,Variance 5,0.3,Noise 5,1.9750000000000003,Total 6,0.6666666666666666,Bias squared 6,1.2600000000000002,Variance 6,0.3,Noise 6,2.2266666666666666,Total 7,0.5714285714285714,Bias squared 7,1.715,Variance 7,0.3,Noise 7,2.5864285714285713,Total 8,0.5,Bias squared 8,2.24,Variance 8,0.3,Noise 8,3.04,Total 9,0.4444444444444444,Bias squared 9,2.8350000000000004,Variance 9,0.3,Noise 9,3.5794444444444444,Total 10,0.4,Bias squared 10,3.5000000000000004,Variance 10,0.3,Noise 10,4.2,Total
In the classical illustration, total error traces a U-shape as complexity rises: shrinking bias initially helps, then growing variance dominates. This is a possible pattern, not a law of model complexity.
Work through the math
At a fixed test input , let , where , , and . For a model fitted to a random training set independent of the test noise, expected squared error decomposes as:
Reading each term:
- Bias: how far the average prediction (over many training sets) is from . A linear model fitted to a nonlinear relationship can have substantial bias.
- Variance: how much the prediction changes with the training set. Highly flexible fits on small datasets can have substantial variance.
- Irreducible: , the conditional noise variance given these input features. It is a lower bound on expected squared prediction error in this setting, not on every realized test error.
The left-hand expectation includes training-set randomness and independent test noise; the bias and variance terms average over fitted models. Neither finite data nor greater complexity requires a strict exchange between bias and variance. More representative data can reduce variance without increasing bias.
Key takeaway: Training and validation errors are diagnostic clues, not measurements of the decomposition. Noise, optimization failure, distribution shift, and leakage can also affect them. Check those possibilities before deciding a model simply needs more or less capacity.
Diagnosis to prescription:
| Symptom | Diagnosis | Levers |
|---|---|---|
| High train error, high val error | Possible underfitting, optimization failure, or high noise | Compare with a baseline; inspect optimization and features before increasing capacity |
| Low train error, large gap to val | Possible overfitting or train/validation mismatch | Check splits and distribution shift; try more data, regularization, or lower capacity |
| Both errors near a credible noise floor | Little remaining reducible error under these conditions | Check held-out performance and relevant subgroups |
Read the implementation
A single-split illustration: fit polynomials of increasing degree and compare train and test error. Estimating bias and variance separately requires repeating training on independent datasets and comparing their predictions with the known signal.
1import numpy as np
2from numpy.polynomial import polynomial as P
3
4rng = np.random.default_rng(0)
5
6def true_f(x):
7 return np.sin(2 * np.pi * x)
8
9def make_data(n):
10 x = rng.uniform(0, 1, n)
11 y = true_f(x) + rng.normal(0, 0.2, n) # signal + irreducible noise
12 return x, y
13
14x_train, y_train = make_data(20)
15x_test, y_test = make_data(500)
16
17for degree in (1, 3, 9, 15):
18 coeffs = P.polyfit(x_train, y_train, degree)
19 train_mse = np.mean((P.polyval(x_train, coeffs) - y_train) ** 2)
20 test_mse = np.mean((P.polyval(x_test, coeffs) - y_test) ** 2)
21 print(f"degree {degree:>2}: train={train_mse:.3f} test={test_mse:.3f}")
22
23# degree 1: high train + high test -> underfit (high bias)
24# degree 3: low train + low test -> good fit (degree 9 tests about the same here)
25# degree 15: ~0 train + high test -> overfit (high variance)Questions and trade-offs
- Conceptual: Define bias and variance in one sentence each, in terms of training-set randomness. (Bias: error of the average prediction vs. truth. Variance: how much the prediction changes across different training sets.)
- Implementation: What do training and validation errors tell you? (High training error suggests checking fit, optimization, and noise. A large gap suggests checking overfitting and distribution mismatch. Neither directly measures bias or variance.)
- Applied: You're overfitting. Name three levers and their possible effects. (More representative data can reduce variance without increasing bias. Stronger regularization or a simpler model can reduce variance while increasing bias; validate the effect.)
- Systems-level: How does cross-validation relate to this decomposition? (It estimates generalization performance under appropriate sampling assumptions. Fold scores are correlated, and their spread is not the prediction-variance term in the decomposition.)
- Failure modes: Does the classic U-curve always hold? (Not always: deep, overparameterized nets can show "double descent," where test error falls again past the interpolation threshold. Know the exception exists.)
Check your understanding
From memory: write the squared-error decomposition and its assumptions, define each term, and explain why training/validation errors do not directly measure bias and variance. Then name one exception to the U-curve. Check against Stages 3 and 5.
Sources and further reading
- scikit-learn, Bias-variance decomposition example: repeated-dataset estimates of bias, variance, and noise.
- Belkin et al., Reconciling modern machine learning practice and the bias-variance trade-off: double descent and the limits of the classical U-curve.
- scikit-learn, Cross-validation: split assumptions and evaluating generalization.
Oliver Perrin
Machine Learning Engineer · Founder, LiminalML
LiminalML brings together concept explanations, mathematical examples, and working visuals. Find more writing by Oliver on the LiminalML Substack.
Keep exploring the idea.
Ask a follow-up in a guided session, work through the self-check, or open the visual in Studio to build on it.