Foundations

The Bias-Variance Tradeoff Derived and Illustrated

Follow a step-by-step derivation of expected squared error into noise, bias and variance, then check it with a worked numerical example.

Key takeaways

  • For squared loss, expected error equals irreducible noise plus squared bias plus variance.
  • Bias and variance are properties of a learning procedure across many possible training sets, not of one fitted model.
  • Shrinking an estimate toward a fixed value adds bias but can cut variance by more, lowering total error.
  • Averaging many models reduces variance most when their errors are weakly correlated.
  • The clean three-part split belongs to squared loss, and capacity does not always trade the two in a simple U shape.

The expected squared error of a learned predictor at any input splits into three parts: noise that no model can remove, bias, which is how far the average fitted model sits from the truth, and variance, which is how much the fitted model changes from one training set to another.

The tradeoff is that settings which lower bias, such as more flexibility, often raise variance. The best choice minimizes their sum, and that can mean deliberately accepting some bias.

The setup

Assume targets are generated as y = f(x) + ε, where f is the unknown true function and ε is noise with mean 0 and variance σ². You draw a training set D, fit a predictor, and call its output at a particular input f̂(x). Because D is random, f̂(x) is random too.

Now imagine a new target y at the same x, with noise independent of D. The question is the average of (y − f̂(x))² over both sources of randomness: which training set you got, and which noise the new point got.

The derivation

Write f for f(x), f̂ for f̂(x), and m for E[f̂], the average prediction over all training sets. Note that m and f are fixed numbers.

E[(y − f̂)²]
  = E[(f + ε − f̂)²]                         definition of y
  = E[(f − f̂)²] + 2·E[ε(f − f̂)] + E[ε²]     expand the square
  = E[(f − f̂)²] + 0 + σ²                    ε has mean 0 and is independent of D

E[(f − f̂)²]
  = E[((f − m) + (m − f̂))²]                 add and subtract m
  = (f − m)² + 2(f − m)·E[m − f̂] + E[(m − f̂)²]
  = (f − m)² + 0 + E[(f̂ − m)²]              E[f̂] = m

Putting the pieces together:

expected squared error = σ²  +  (m − f)²  +  E[(f̂ − m)²]
                         noise   bias²        variance

Bias is defined as m − f. Averaging over inputs x gives the same split for the model's overall expected error. Both cross terms vanished for specific reasons, so the independence of the new noise from the training data is a real requirement.

What each term means in words

Noise, σ², is the spread of targets among cases with identical inputs. Two flats with the same recorded features rent for different amounts because the features leave things out. A better model cannot remove this, though better features can, since adding information changes which cases count as identical.

Bias describes a systematic miss. Retrain on a hundred fresh datasets, average the hundred predictions, and compare the average with the truth. If a straight line is fitted to a curved relationship, the average line is still wrong, and wrong in the same direction each time.

Variance describes disagreement among those hundred models. If their predictions at x are scattered widely, then the one you actually have is a lottery draw, even when the average of all of them is excellent.

You only ever receive one training set. That is why variance hurts: you cannot average over datasets you do not have. Much of ensemble learning is a clever attempt to imitate that average from a single sample.

A worked example you can check by hand

Strip the problem to estimating one number μ from n noisy observations with variance σ². The sample mean ȳ is unbiased with variance σ²/n. Consider instead c·ȳ, which shrinks the estimate toward zero when c is below 1.

bias     = E[c·ȳ] − μ = (c − 1)·μ
variance = c²·σ²/n
error in estimating μ = (1 − c)²·μ² + c²·σ²/n

Take μ = 2, σ² = 16 and n = 4, so σ²/n = 4 and μ² = 4.

c Bias² Variance Sum
0 4.00 0.00 4.00
0.25 2.25 0.25 2.50
0.5 1.00 1.00 2.00
0.75 0.25 2.25 2.50
1 0.00 4.00 4.00
Example: estimation error for the shrunken mean c·ȳ
c = 0 (ignore the data) 4squared error c = 0.25 2.5squared error c = 0.5 2squared error c = 0.75 2.5squared error c = 1 (plain sample mean) 4squared error c = 0 (ignore the data) 4squared error c = 0.25 2.5squared error c = 0.5 2squared error c = 0.75 2.5squared error c = 1 (plain sample mean) 4squared error

Hypothetical example: the numbers are made up to show the method, not a quote or an average.

The unbiased estimator is no better than ignoring the data entirely, and halfway beats both. Setting the derivative to zero gives the best factor, c = μ² / (μ² + σ²/n), which is 0.5 here.

There is a catch: that formula needs μ, the thing you are trying to estimate. In practice the amount of shrinkage is a setting you choose with validation data or from prior knowledge. Ridge regression applies this idea to many coefficients at once. As n grows, σ²/n shrinks, the best c approaches 1, and less shrinkage is wanted.

Where each part comes from in real models

k-nearest neighbors shows the tradeoff cleanly. Hold the training inputs fixed and predict at x₀ by averaging the targets of the k nearest points. With independent noise:

variance = σ²/k
bias     = (average of f over the k neighbors) − f(x₀)

Raising k divides the variance down. It also pulls in neighbors farther away, where f may differ from f(x₀), so bias tends to grow.

Change Usual effect on bias Usual effect on variance
Deeper decision tree Down Up
Stronger weight penalty Up Down
More training data Little change for a fixed model Down
Better informative feature Down Depends
Averaging resampled models Little change Down

These are tendencies. Check them on your own validation curves.

Averaging and the role of correlation

Suppose you average B predictors that each have variance s², with the same correlation ρ between any pair. The variance of the average is

ρ·s² + (1 − ρ)·s²/B

With s² = 1, ρ = 0.5 and B = 10, that is 0.5 + 0.05 = 0.55. With B = 1,000 it is about 0.50. The second term melts away as you add models, while the first stays. To go further you must make the models less alike, which is why random forests use random feature subsets in addition to resampled data.

Using the diagnosis

The split suggests different actions depending on which term dominates.

If bias dominates, errors persist as data grows and training error is already high. Add relevant features, use a more flexible form, or relax a penalty that is holding the model back. Collecting more rows of the same kind will mostly confirm the same wrong shape with greater confidence.

If variance dominates, small changes in the training data produce visibly different predictions, and validation error sits well above training error. Gather more data, constrain the model, drop weak features or average several fits.

If noise dominates, both knobs stop helping. The remaining routes are to measure something new, to clean up inconsistent labels, or to change the question to one the inputs can answer. Report predictions as ranges where a single number would suggest false precision.

A quick probe for variance is to train the same configuration on several random subsets and compare predictions for a fixed set of cases. Large disagreement on particular cases also marks where individual predictions deserve less trust.

Estimating the parts in practice

With synthetic data, where f is known, you can measure all three terms directly: generate many training sets, fit the model on each, and at fixed test inputs compute the mean and variance of the predictions. It is a worthwhile exercise.

With real data you usually cannot separate bias from noise, because f is unknown. Resampling methods such as the bootstrap give a sense of how much your predictions move. Comparing training and validation error, as in diagnosing overfitting and underfitting, is the practical proxy.

Limits of the picture

The additive form above is specific to squared loss. For zero-one classification loss, bias and variance can be defined in several ways and they interact: extra variance can even help on an input where the average prediction is wrong.

The familiar U-shaped curve of error against complexity is also a common pattern and not a theorem. The identity always holds under its assumptions, but nothing in it says variance must rise steadily with parameter count. In some settings test error falls again after the model grows past the point where it can fit the training data exactly, a behavior called double descent. The training method's own preferences among solutions matter a great deal there.

Common questions

Is high bias the same as a biased or unfair model?

No. Here bias is a statistical quantity: a systematic offset of the average prediction from the true function. Unfairness concerns how errors and decisions affect different groups. A model can have low statistical bias against its recorded labels and still be unfair, for instance if the labels themselves are skewed.

Does the decomposition tell me which model to pick?

Not directly. It explains why a model errs, while selection still rests on measured held-out error, which includes all three terms together. The split is most useful for deciding what to try next. If you suspect variance, more data or averaging is a reasonable experiment. If you suspect bias, spend the effort on features or a more flexible form, then measure again.

Can I reduce both at once?

Often, yes. More relevant data reduces variance and lets you afford flexibility that lowers bias. A model whose assumptions match the problem well can have lower bias and lower variance than a poorly matched one. The tradeoff bites when data and knowledge are held fixed and you turn a single complexity setting.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic