← All AI/ML articles

The bias–variance tradeoff, visualised.

A model can be wrong because it is too simple, or because it chases noise. Fit the same model to 60 different samples and see both kinds of error with your own eyes.

1. Fit many samples2. Compare to the truth3. Split the error
White = true function. Thin lines = the model fitted to each of 60 different random training sets. Cyan = their average. Dots = one example training set. Dashed vertical line = the point x₀ examined in the maths below.
Bias²0
Variance0
Expected test error0
“Best degree” means the lowest estimated expected test error among degrees 1 to 12 under the current settings, from 60 simulated training sets. It is not the best degree for every dataset, and a new random simulation can change it, especially when several degrees have nearly equal error.
Behind the scenes · 1

Two ways to be wrong

Bias is how far the average fit sits from the truth: a model that is too simple misses the shape the same way every time. Variance is how much the fits differ from each other when the training sample changes: a flexible model follows the noise in whichever sample it sees. Raise the degree and watch the cyan average hug the white curve while the thin lines spread out.


Every degree from 1 to 12 at your current noise, sample size and λ. Log scale. Click to choose a degree.
Pink bias² (systematic miss) Cyan variance (sensitivity to sample) White test error = bias² + variance + σ² Amber training error (on the noisy sample) Grey noise floor σ² (irreducible)
Behind the scenes · 2

Training error keeps falling, test error does not

Training error only measures how well the model fits the sample it saw, so more flexibility almost always lowers it. Test error also pays for variance. The table compares them at several degrees, using your current settings.


All numbers are averages over the 60 simulated training sets. The highlighted row is your current degree.

Behind the scenes · 3

Three levers you control

Complexity ↑

Here, a higher polynomial degree. Bias usually falls and variance usually rises.

Regularisation ↑

Ridge λ shrinks coefficients. It typically lowers variance at the cost of some extra bias.

More data ↑

Variance usually falls. Bias from a model that is too simple does not.

These are tendencies, not guarantees. Move each slider and read the tiles to see them on this problem.

The mathematics

The mathematics behind bias and variance

Numbers below come from the same 60 simulated datasets as the picture. Because they are estimated from 60 samples, they carry some Monte Carlo error.

A. The setup

y = f(x) + ε   ,   E[ε] = 0  ,  Var(ε) = σ²

B. The decomposition (squared error)

E[(y − ƒ̂(x))²] = (E[ƒ̂(x)] − f(x))² + Var(ƒ̂(x)) + σ²

The equation holds pointwise, at each x. The expectations are over the randomness of the training set, and the test observation y = f(x) + ε has fresh, independent, zero-mean noise with variance σ², independent of the training set. Averaging the three terms over the test grid gives the numbers below. The noise floor σ² is the theoretical minimum expected test MSE under this data-generating process, reached only by predicting f(x) exactly. A fitted model generally will not attain it.


C. One point in detail

bias(x0) = E[ƒ̂(x0)] − f(x0)   ,   Var(x0) = E[(ƒ̂(x0) − E[ƒ̂(x0)])²]

D. What the simulation can and cannot tell you

Reading it
  • Bias and variance can be computed here only because we know the true f and can draw many training sets. With real data you have one sample and an unknown f.
  • In practice you estimate generalisation error with a validation set or cross-validation, and tune complexity and regularisation against it.
  • The decomposition is exact for squared error. Other losses have related but different trade-offs.
  • The U-shaped test curve is the classic picture, not a law: very large, heavily over-parameterised models can behave differently (for example “double descent”).
Experiment

Break it on purpose

Underfit a curve

Fit a straight line (degree 1) to the smooth curve. Do the 60 fits agree with each other, and do they agree with the truth?

Overfit a tiny sample

Degree 12 with only 15 noisy points. Watch the fits scatter from sample to sample.

Add more data

Keep a flexible model (degree 9) and raise the sample size from 15 to 80. See which error term moves.

Check yourself

Three quick questions

Key takeaways

  • Bias is systematic error from a model that is too simple; variance is sensitivity to the particular training sample; noise is the part no model can remove.
  • For squared error, expected test error = bias² + variance + noise.
  • Complexity typically lowers bias and raises variance; regularisation and more data typically lower variance.
  • Training error alone is a poor guide. Use validation or cross-validation to choose complexity.
  • Not a law: the U-shaped curve is a useful default picture, and some modern models behave differently.
← Back to all articles