Search

Search papers and lessons

Bias-Variance Tradeoff

Level 3 · 14 min read

A model's test error splits into bias, the error from being too rigid, and variance, the error from chasing noise in the training data, so making a model more flexible lowers one and raises the other.

On this page

  • Colour = topic mix
  • Probability
  • Losses & regularization
  • Learning basics
  • Discrete math
  • Sign in to see your progress

TL;DR

When you fit a model to data, its error on new data comes from three sources. Bias is the error from a model that is too rigid to capture the true pattern. Variance is the error from a model that is so flexible it fits the quirks of one particular training set, and would fit different quirks if the training set were different. Irreducible noise is the randomness no model can remove. Making a model more flexible usually lowers bias and raises variance, so the best model sits in the middle.

Where you'll see it: in choosing the degree of a polynomial, the depth of a decision tree, or the strength of a regularisation penalty, and in why ensembles such as Bagging and early stopping help.

Intuition

Imagine you are shown five noisy measurements of a smooth curve and asked to predict the value somewhere new. There are two easy ways to get it badly wrong.

The first is to draw a straight line no matter what the points look like. The line misses the curve's bend every time you draw a new set of points. Its mistakes are consistent, and that consistency is bias.

The second is to draw a wiggly curve that passes through every point. It is perfect on the points you have, but a different set of noisy points would produce a completely different wiggle. Its mistakes change from one training set to the next, and that instability is variance. Fitting the noise this way is Overfitting; fitting too little is underfitting.

A good model is flexible enough to follow the real curve but not so flexible that it follows the noise. Nothing removes the scatter of the measurements themselves; that part of the error is fixed.

Here is the picture in one sentence: a rigid model is wrong in the same direction every time, and a flexible model is right on average but wrong in a different direction each time.

The math

Setting up

Assume the world produces targets by a true function plus noise:

y=f(x)+ε,E[ε]=0,Var(ε)=σ2.y = f(x) + \varepsilon, \qquad \mathbb{E}[\varepsilon] = 0, \qquad \mathrm{Var}(\varepsilon) = \sigma^2.

Here f(x)f(x) is the true signal at input xx, ε\varepsilon is random noise with mean zero and variance σ2\sigma^2, and yy is the observed target. We train a learning algorithm on a random training set D\mathcal{D}, which produces a predictor f^D(x)\hat{f}_{\mathcal{D}}(x). Because the training set is random, the predictor is random too. Its expected value over training sets is written ED[f^(x)]\mathbb{E}_{\mathcal{D}}[\hat{f}(x)].

Define, for a fixed input xx:

  • Bias: Bias[f^(x)]=ED[f^(x)]−f(x)\mathrm{Bias}[\hat{f}(x)] = \mathbb{E}_{\mathcal{D}}[\hat{f}(x)] - f(x), the gap between the average prediction and the truth.
  • Variance: Var[f^(x)]=ED[(f^(x)−ED[f^(x)])2]\mathrm{Var}[\hat{f}(x)] = \mathbb{E}_{\mathcal{D}}\big[(\hat{f}(x) - \mathbb{E}_{\mathcal{D}}[\hat{f}(x)])^2\big], how much predictions spread around their own average.

The decomposition

Take a fresh test point (x,y)(x, y) with y=f(x)+εy = f(x) + \varepsilon, independent of the training data. The expected squared error (the mean squared error averaged over training sets and noise) is

E[(y−f^(x))2]=Bias[f^(x)]2+Var[f^(x)]+σ2.\mathbb{E}\big[(y - \hat{f}(x))^2\big] = \mathrm{Bias}[\hat{f}(x)]^2 + \mathrm{Var}[\hat{f}(x)] + \sigma^2.

Derivation. Write the error as three pieces that add to y−f^y - \hat{f}:

y−f^=(f−E[f^])⏟bias term+(E[f^]−f^)⏟variance term+ε.y - \hat{f} = \underbrace{\big(f - \mathbb{E}[\hat{f}]\big)}_{\text{bias term}} + \underbrace{\big(\mathbb{E}[\hat{f}] - \hat{f}\big)}_{\text{variance term}} + \varepsilon.

Square the sum and take expectations. The two cross terms that contain ε\varepsilon vanish, because ε\varepsilon has mean zero and is independent of the training set. The cross term between the bias and variance pieces vanishes because E[E[f^]−f^]=0\mathbb{E}[\mathbb{E}[\hat{f}] - \hat{f}] = 0. What remains is the squared bias (the first piece is a constant once xx is fixed), the variance, and E[ε2]=σ2\mathbb{E}[\varepsilon^2] = \sigma^2.

The three terms have different owners. The noise σ2\sigma^2 belongs to the world and no model can lower it. The bias belongs to the model's assumptions. The variance belongs to how sensitive the fitted model is to the particular data it saw.

A tiny calculation

Suppose the true mean of a population is μ=2\mu = 2 and each observation has variance σ2=1\sigma^2 = 1. We estimate μ\mu from n=4n = 4 observations, so the sample mean yˉ\bar{y} has variance σ2/n=0.25\sigma^2/n = 0.25. Consider two estimators:

  • Plain sample mean, μ^=yˉ\hat{\mu} = \bar{y}. It is unbiased, so its bias is 00, and its variance is 0.250.25. Its excess error (bias squared plus variance) is 0.250.25.
  • Shrunken mean, μ^=c yˉ\hat{\mu} = c\,\bar{y} for some cc. Its bias is (c−1)μ=2(c−1)(c - 1)\mu = 2(c-1), and its variance is c2×0.25c^2 \times 0.25. Its excess error is 4(c−1)2+0.25c24(c-1)^2 + 0.25c^2.

With c=0.9c = 0.9 the excess error is 4(0.01)+0.81(0.25)=0.04+0.2025=0.24254(0.01) + 0.81(0.25) = 0.04 + 0.2025 = 0.2425, which is slightly better than 0.250.25. Shrinking adds a little bias and removes more variance. Minimising over cc gives c=16/17≈0.941c = 16/17 \approx 0.941 and an excess error of 68/289≈0.23568/289 \approx 0.235. The sweet spot is biased, which is the central message of the tradeoff. The optimum is not zero bias; it is the lowest total.

123456012345model complexity (for example, polynomial degree)error
  • bias squared
  • variance
  • total test error
  • irreducible noise
Schematic curves, not measured data. Bias falls as complexity grows, variance rises, and total error is lowest at the marked point, above the irreducible floor.

Where the curves come from

The schematic above is not arbitrary. For a model family with kk free parameters fitted by least squares, the variance term tends to grow roughly in proportion to kk divided by the number of training points. The bias term tends to shrink as the family gets richer, because more shapes become reachable. The total is therefore U-shaped in complexity, with the minimum where the marginal drop in bias equals the marginal rise in variance.

Worked examples

Example
Polynomial degree on a sine curve

The true signal is f(x)=sin⁡(x)f(x) = \sin(x) on [0,π][0, \pi] with noise σ=0.3\sigma = 0.3. We fit polynomials of degree 1, 3 and 9 to 20 random training points, many times over.

  1. Degree 1 (a straight line). The line cannot follow a hump, so the average prediction is far from sin⁡\sin in the middle. Bias is large; variance is small because a line barely changes from one training set to the next.
  2. Degree 3. The average prediction is close to sin⁡\sin across the interval. Bias is small. Variance is moderate.
  3. Degree 9. Each fitted curve passes almost exactly through its 20 points and swings wildly between them. The average prediction is close to sin⁡\sin, so bias is small, but the spread across training sets is large near the ends of the interval.
  4. Interpretation: degree 3 has the lowest total error here, not because it has the least bias, but because it has the best combination. Degree 9 is a textbook case of a model that is unbiased on average and terrible on any single draw.
Example
Test error versus training error

Illustrative numbers: a decision tree is grown with no depth limit on 200 labelled examples and reaches zero training error. Its test error is 25%.

  1. Zero training error means the tree has memorised the training labels, including their noise.
  2. A new training sample would produce a different tree, with different splits, so its predictions vary: variance is high.
  3. Pruning the tree to depth 4 raises the training error to about 10% and drops the test error to about 14%.
  4. Interpretation: the drop in test error came from lowering variance more than the bias increased. Training error is a poor guide to test error once the model is flexible enough to memorise.

Tradeoffs and failure modes

Choosing a model is choosing a point on the bias-variance curve. The table lists how the tradeoff shows up in practice.

SituationSymptomLikely causeBetter choice
Training and test error both highModel misses obvious structureHigh bias (underfitting)More features, a richer model, or less regularisation
Training error low, test error much higherModel fits noiseHigh variance (overfitting)More data, stronger regularisation, early stopping, or simpler model
Small dataset, flexible modelResults change a lot with new samplesVariance dominated by sample sizeCollect data, or average several models (bagging)
Very large datasetBoth errors close to the noise floorLittle left to reduceFocus on the problem definition or measurement quality

Some practical warnings:

  • Do not read the tradeoff from training error. Training error falls monotonically with flexibility. Only held-out error, from a validation set or cross-validation, shows the U-shape.
  • Noise sets a floor. If the irreducible σ2\sigma^2 is large, even a perfect model has high error, and tuning complexity further will look like it helps less than it does.
  • Variance is not just about parameter count. Heavy regularisation, data augmentation and averaging all reduce variance without changing the model class, and that is why they are often the better fix.
  • The classical picture is incomplete for very large models. Some over-parameterised neural networks keep improving past the point where classical theory predicts overfitting. Belkin and colleagues called the resulting curve "double descent". Treat the U-shape as the default mental model, and check the held-out curve for your own model.

History

The name is modern, but the idea is old. Statisticians had known since the 1950s and early 1960s that biased estimators can beat unbiased ones in mean squared error. Charles Stein showed in 1956 that the sample mean is inadmissible for estimating several normal means at once, and William James and Stein gave an explicit shrinkage estimator in 1961. Regularised methods such as ridge regression, which trade bias for lower variance, came from the same line of thought.

The tradeoff as a named dilemma was popularised by Stuart Geman, Elie Bienenstock and René Doursat in a 1992 paper on neural networks, "Neural Networks and the Bias/Variance Dilemma". They framed the question as the core obstacle to learning from finite data, and the phrase spread through machine learning textbooks over the following decade.

It caught on because it explained two things that looked contradictory at the time: why more complicated models sometimes generalise worse, and why averaging over many models can improve them. The decomposition gives both a single explanation. In 2018 and 2019 Belkin and coauthors showed that very large models can break the classical U-shape, which is why the tradeoff is now treated as a useful default rather than a law.

Check yourself

QuestionName the three parts of expected test error and say which one a model cannot reduce.Show answer

The three parts are squared bias, variance, and irreducible noise σ2\sigma^2. The noise cannot be reduced by any model, because it comes from the randomness in the targets themselves. Bias comes from the model's assumptions about the shape of the function, and variance comes from sensitivity to the particular training sample.

QuestionA predictor has bias 0.3 and variance 0.5 at a point, and the noise variance is 0.2. What is its expected squared error there?Show answer

Add the three terms: 0.32+0.5+0.2=0.09+0.5+0.2=0.790.3^2 + 0.5 + 0.2 = 0.09 + 0.5 + 0.2 = 0.79.

QuestionWhy does an unbiased estimator not always give the lowest error?Show answer

Because expected error also includes variance. An unbiased estimator can have large spread across samples, and a slightly biased estimator with much smaller spread can have lower total error. The shrunken mean with c=0.9c = 0.9 in the worked calculation beats the plain sample mean for exactly this reason, even though it is biased.

QuestionA deep neural network has near-zero training error and much higher test error. You can either add more training data or make the network smaller. Which lever targets which term, and what would you check first?Show answer

More data mainly lowers variance, because the fitted model depends less on the particular sample. A smaller network lowers variance by restricting the model class, but it may raise bias if it becomes too rigid. Before changing anything, check the held-out curve as a function of model size and data size, since very large models may not follow the classical U-shape and the answer depends on where you sit on the curve.

Sources