Skip to content

Learning from dataLesson 6 of 6

Where the error comes from

Expected prediction error, bias, and variance

The previous decomposition scored one fixed predictor. Now ask what happens if you repeat the entire training process with different data.

Draw a training dataset DD and fit a model f^D\hat f_D. Draw a different dataset from the same population and the fitted model usually changes. At one fixed input x0x_0, those models give different predictions.

There are now two sources of randomness: which training dataset you got, and which future output you are asked to predict.

experimentkeep fixedvary
possible outputs at x0x_0the inputthe fresh output Y0Y_0
predictions at x0x_0the input and training methodthe training dataset DD

The second experiment defines the average prediction ED[f^D(x0)]\mathbb E_D[\hat f_D(x_0)] and the prediction variance VarD(f^D(x0))\operatorname{Var}_D(\hat f_D(x_0)). The subscript DD tells you what the averaging is over.

The displayed averages and variances are estimates from simulated datasets. A small collection of fits can have an average far from its theoretical expectation, especially near the edges.

Let fˉ(x0)=ED[f^D(x0)]\bar f(x_0)=\mathbb E_D[\hat f_D(x_0)]. This is the population average prediction over hypothetical repeated training datasets—not the mean of the observed outputs.

At x0x_0, define bias as that average prediction minus the true conditional mean:

Bias(x0)=fˉ(x0)f(x0).\operatorname{Bias}(x_0)=\bar f(x_0)-f(x_0).

For each fixed dataset, the earlier result gives expected error (f(x0)f^D(x0))2+σ2(f(x_0)-\hat f_D(x_0))^2+\sigma^2. Now average that expression over datasets. Apply the same variance identity to the random prediction f^D(x0)\hat f_D(x_0):

R(x0)=ED,Y0x0[(Y0f^D(x0))2]=(fˉ(x0)f(x0))2squared bias+VarD(f^D(x0))prediction variance+σ2output noise.\begin{aligned} R(x_0)&=\mathbb E_{D,Y_0\mid x_0}[(Y_0-\hat f_D(x_0))^2]\\ &=\underbrace{(\bar f(x_0)-f(x_0))^2}_{\text{squared bias}}\\ &\quad+\underbrace{\operatorname{Var}_D(\hat f_D(x_0))}_{\text{prediction variance}}+\underbrace{\sigma^2}_{\text{output noise}}. \end{aligned}

We assume the new output is independent of the training data, conditional on the fixed input. Its zero-mean noise therefore contributes no cross term. If output variance depends on the input, replace σ2\sigma^2 with σ2(x0)\sigma^2(x_0).

Bias asks whether the average prediction misses. Variance asks whether the fitted models disagree. Noise asks how much future outputs vary even at the same input.

For a small toy experiment, suppose a training method produces each of the five listed predictions with equal probability. The true conditional mean is 4 and the output noise variance is 1.

predictionsmeanbiasbias²prediction varianceexpected error
7, 7, 8, 6, 77390.410.4
4, 5, 4, 3, 44000.41.4
1, 7, 4, 6, 24005.26.2

For the last row, variance is (9+9+0+4+4)/5=5.2(9+9+0+4+4)/5=5.2. The average prediction is correct, but an individual fit can still miss badly.

For a real simulation with only five sampled fits, these numbers would be estimates of the theoretical quantities. More simulation runs can improve those estimates; that is different from adding more training examples to each fit.

Expected error is different from one test-set score

Section titled “Expected error is different from one test-set score”

R(x0)R(x_0) averages over training datasets and future outputs at a particular input. To obtain overall expected error, also average over inputs: R=EX[R(X)]R=\mathbb E_X[R(X)].

A measured test MSE uses one fitted model and one finite test set. It is a noisy estimate of that fitted model’s performance. It is not exactly equal to the bias–variance decomposition across hypothetical datasets.

In the classical example here, a rigid line cannot follow a curved relationship, while a high-degree polynomial can respond strongly to the noise in a small training set. This often produces decreasing bias, increasing prediction variance, and a U-shaped expected-error curve.

The decomposition is an identity under the stated conditions. Those particular curve shapes are a pattern, not a theorem about every learning method. Regularization, different model families, and sufficiently large models can produce different patterns. The advanced example called double descent is one reason to avoid treating the U as universal.

A schematic classical example, not measurements from the simulation above. Explain the mechanism behind each curve rather than memorizing its color or number.

These are starting hypotheses to check with validation data:

situationa reasonable starting pointreasoning
many observations, few featuresallow more flexibilitymore data can stabilize a flexible fit
many features, few observationsconstrain or regularize the fitotherwise many very different models may fit the same data
strongly nonlinear relationshipallow a suitable nonlinear shapean inappropriate straight line can retain approximation error
large output noiseuse stronger smoothing or regularizationsmall sample fluctuations are less reliable

More data often reduces prediction variance. It does not make a straight-line model capable of representing every curved relationship. However, an estimator’s bias can also depend on sample size; “more data never changes bias” is too broad.

Read an unfamiliar problem, review the cheat sheet, or try mixed practice.

Definition

Read the full glossary entry →