If you collected the data again, would you get the same curve? Below, one curve is measured 20 times over, each time with fresh noise, and a polynomial is fitted to each set of readings. Before the clip plays: which degree will stay closest to the true curve?
Refit on new data, and watch the curves
20 training sets of 12 noisy readings of a curve; polynomial fits up to degree 6.
Degree 1, a straight line, fitted to each of 20 training sets in turn: the same 12 positions, new noise each time.
Describe this picture
One panel of against , with from −1 to 1 and from −2 to 2.5. The true curve is drawn thick: a cubic that rises to a hump, dips and rises again. There are 20 training sets, each with 12 noisy readings of the curve at the same 12 positions. The clip runs three blocks, for degree 1, 3 and 6. In each, the 20 fits appear one after another, each with its own 12 readings shown as dots while it is drawn, and stay as a bundle of thin lines; then their average is drawn dashed. The captions: at degree 1 “every fit is nearly the same line, and all miss the curve the same way”; at degree 3 “the fits follow the curve and stay close together”; at degree 6 “each fit chases its own dots: the bundle spreads, most near the ends”. Readouts, each averaged over the 12 positions: “bias², measured” beside “bias², expected”, “variance, measured” beside “variance, expected”, and the degree. After the clip a slider, “Polynomial degree”, runs from 0 to 6 and starts at 6; the training sets stay the same at every degree, so only the model changes. With reduced motion the bundles for degree 1, 3 and 6 are shown side by side.
One curve, many training sets
The true curve is on . I built it from a cubic on purpose, so that you can see a model match it exactly; real curves rarely oblige. It starts at 1 at , rises to 1.385 at , falls to −0.695 at and returns to 1 at .
Each reading is the curve plus noise: at the positions , . The noise has mean 0 and standard deviation , independent from reading to reading. Here is a noise’s standard deviation, as in statistics; in signal processing a bare means something else. The 12 readings, one training set, are examples.
A polynomial of some degree is fitted to each set by least squares, as in Least squares:
with coefficients , counted by . This is linear regression with the features ; Features and basis functions builds that idea.
One fit tells me little. The point of the picture is the bundle: the same model fitted to 20 training sets that differ only in their noise. Now the answer to the question. At degree 1 the 20 lines are nearly the same, and all miss the curve in the same places. At degree 6 the fits are centred on the curve, but each bends towards its own dots, and the bundle spreads, most near the ends. Degree 3 is both tight and on the curve. Drag the degree from 0 to 6 and watch the bundle tighten onto the curve, then spread.
Bias and variance of a model
Imagine fitting not 20 training sets but every possible one, and averaging the fits at a position . That average is the expected fit, , the average over training sets. Two things can go wrong.
The expected fit can miss the curve. That miss is the bias of the model at :
The fits can also scatter round their own average. That scatter is the variance of the model at :
Both describe the bundle, not one fit. Variance here is the spread of the fitted curves, not the noise in the readings. And this bias is a property of a model’s average fit; it is not the bias term of a linear model.
In probability and statistics · bias and variance of an estimator
Estimators: bias and variance in the statistics course splits the error of one estimated number into the same two parts. Here the estimate is a whole curve, and each position has its own bias and variance.
With only 20 fits, the instrument averages what it has. I write for the average of the fits at ; the bar marks an average. The readout “bias², measured” is the squared miss of that average, and “variance, measured” the spread of the 20 fits about it, each averaged over the 12 positions. The average of only 20 fits still carries a twentieth of the variance in its squared miss, so the measured bias² sits a little above the true one, and the “expected” readout beside it adds that twentieth: . At degree 3 the true bias is 0, yet the expected readout shows 0.0015, which is .
Three parts of the error
What matters is the error on a new reading, , with fresh noise of mean 0 and variance , independent of the training sets. Its squared error, averaged over training sets and over the new noise, splits into three parts:
Here is why. Write . Square it and average. The new noise is independent of the fit and has mean 0, so every cross term with averages to 0. The last bracket also has mean 0, so its cross term with the fixed middle bracket vanishes too. What is left are the three squares: , the bias squared, and the variance.
The noise is the floor: no model can predict fresh noise. Bias and variance are the two parts a choice of model can change.
Averaged over the positions
Average each part over the 12 training positions; a bar over a quantity marks that average. Least squares then gives three exact results, when the positions stay fixed and only the noise is redrawn:
Once the bias has gone, each extra coefficient adds to the variance, the training error falls by the same amount and the error on new readings rises by it. These are the formulas of Overfitting and model choice, now with a bias term for models that cannot reach the curve.
- error on new readings
- training error
- bias²
- variance
- noise σ²
Describe this picture
One panel against the degree, from 0 to 6, drawn from the exact formulas for the 12 positions and . Five lines join the points: bias², variance, the noise level 0.09, the error on new readings and the training error. Bias² falls from 0.5624 to 0 at degree 3 and stays there; variance climbs by 0.0075 per degree, from 0.0075 to 0.0525; the training error falls all the way to degree 6, to 0.0375. The error on new readings falls, then rises, in a U, and a ring marks its lowest point, 0.1200 at degree 3. The caption says the U holds for these fits: very flexible models can behave differently. There is no control.
The U-shaped curve of Overfitting and model choice is the sum of these parts. On the left, bias dominates: the model is too simple. On the right, variance dominates: the model is flexible enough to follow the noise. In between, at degree 3, bias has reached 0 while variance is still small.
Watch out
The model with the lowest training error is not the best. Here degree 6 has the lowest training error and a higher error on new readings than degree 3.
More data
More readings shrink one part and not the other. With 120 positions instead of 12, is ten times smaller at every degree. Bias does not change in that way: a straight line cannot follow a cubic however many readings it gets.
Describe this picture
Four small panels of against from −1 to 1, each with the true curve drawn thick, 20 thin fits and their dashed average. The top row is degree 1, the bottom row degree 6; in each row the left panel has 12 readings per training set (the sets of the clip) and the right panel 120. On a narrow screen the panels stack one per row. Above each panel are its measured bias² and variance. At degree 6 the bundle spreads widely at 12 readings, most near the ends, and lies close together on the curve at 120: its variance falls about tenfold, to 0.0060. At degree 1 both bundles are nearly the same straight line, tighter still, and both miss the curve the same way: bias² 0.2156 at 12 readings and 0.2316 at 120. There is no control.
So “enough data” cures variance, never bias. And whether a model “overfits” is not a yes-or-no question: it depends on how much data it has, and by how much its error on new readings exceeds the best.
Worked example
Take the 12 positions : , with , so .
The sums. Over the 12 positions, , and .
Odd and even parts. The curve splits into an odd part, , and an even part, . On positions symmetric about 0, least squares fits the two separately: odd powers fit the odd part and even powers the even part.
- The odd part left unfitted (degree 0) leaves . After the best slope (degrees 1 and 2) it leaves . From degree 3 it leaves 0.
- The even part, after the best constant (degrees 0 and 1), leaves . From degree 2 it leaves 0.
Bias². Average over the 12 positions, with on the odd part:
- degree 0: ;
- degree 1: ;
- degree 2: ;
- degrees 3 to 6: 0.
The table. Variance is , training error and error on new readings :
| Degree | Coefficients | Bias² | Variance | Training error | Error on new readings |
|---|---|---|---|---|---|
| 0 | 1 | 0.5624 | 0.0075 | 0.6449 | 0.6599 |
| 1 | 2 | 0.2151 | 0.0150 | 0.2901 | 0.3201 |
| 2 | 3 | 0.1293 | 0.0225 | 0.1968 | 0.2418 |
| 3 | 4 | 0 | 0.0300 | 0.0600 | 0.1200 |
| 4 | 5 | 0 | 0.0375 | 0.0525 | 0.1275 |
| 5 | 6 | 0 | 0.0450 | 0.0450 | 0.1350 |
| 6 | 7 | 0 | 0.0525 | 0.0375 | 0.1425 |
The training error falls at every degree. The error on new readings is lowest at degree 3, 0.12, and each degree after it adds , one more coefficient’s share of the noise. Degree 6 is 0.0225 worse than degree 3. Is it overfitting? It is worse by a measurable amount, which is a better answer than yes or no.
At 120 positions, , the variance falls tenfold: degree 6’s is . Bias² does not fall: degree 1’s is 0.2316 and degree 2’s 0.1427, a little above their values at 12 positions and close to their values over the whole interval, and , which more positions approach. More data cannot remove bias.
The floor. No model does better on new readings than , the noise itself.
Where you’ll meet this
Calibrating a sensor. A thermocouple’s voltage is turned into a temperature by a polynomial. Too low a degree misses the true curve everywhere; too high a degree follows the noise in the calibration readings.
Nearest neighbours. In Nearest neighbours, is the high-variance end: each stray training dot moves the answer. A large averages many dots and moves towards bias.
Choosing a setting. On real data the true curve is unknown, so bias cannot be measured. Validation and cross-validation estimates the error on new readings directly, Learning curves shows which part more data would help, and Ridge regression trades a little bias for less variance.
In signal processing · choosing a model order
Parametric models and linear prediction in the signal processing course chooses how many past samples to predict from. Too few coefficients miss the signal’s shape; too many fit the noise of one recording. It is the same trade.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Bias | expectation over training sets | |
| Variance | the spread of the fits, not of the noise | |
| Error on a new reading | at the same positions; noise independent of the training sets | |
| Average variance | coefficients, fixed positions | |
| Training error | falls as the degree rises | |
| New readings | at the same positions; lowest where bias has gone and is small | |
| More data | variance falls, bias stays | |
| Floor | no model predicts fresh noise |