Contents
- 01Introduction
- 02Setting and notation
- 03Intuition
- 04The decomposition and its proof
- 05A warm-up you can do by hand
- 06The experiment
- 07Models where every term has a formula
- 08Diagnosing bias and variance in practice
- 09Fixing high bias and high variance
- 10Beyond the classical picture
- 11Interview questions and model answers
- 12Summary
- References
06The experiment: polynomial regression
We now measure all three terms for a real learning procedure, as in the companion video.
6.1Setup
The truth is f(x)=\sin(2.3\pi x+0.2) on [0,1]; the noise is Gaussian with \sigma=0.3, so \sigma^2=0.09; each training set has n=15 inputs spread evenly over [0,1] with a small random jitter. The learning procedure is “fit a polynomial of degree d by least squares”. Since we know f, we can estimate bias and variance directly by Monte Carlo:
- Draw R=500 independent training sets \D_1,\dots,\D_R.
- Fit the procedure to each, obtaining \fhat_1,\dots,\fhat_R, and evaluate them on a fine grid of inputs.
- Estimate the average model, \fbar(x)\approx\frac1R\sum_r\fhat_r(x).
- Estimate \Bias^2(x)=(\fbar(x)-f(x))^2 and \Var(x)\approx\frac1R\sum_r(\fhat_r(x)-\fbar(x))^2, and average both over the grid.
With 500 training sets, the Monte Carlo error in these averages is small compared with the differences we discuss.
6.2Three models
Figure 4 shows twenty fits for three degrees, together with one of the training sets. The straight line (degree 1) barely changes between training sets, but every fit misses the curve in the same way: high bias, low variance. The degree-12 polynomial bends to pass near every training point, so each training set produces a wildly different curve, yet on average it follows the truth: low bias, high variance. Degree 4 sits in between: its fits stay close to the curve and close to each other.
6.3All twelve degrees
Table 1 lists the measured terms for every degree from 1 to 12. Bias falls quickly as the degree grows: by degree 5 the average fit is essentially exact. Variance rises slowly at first and then explodes, because with only fifteen points a degree-12 polynomial has almost as many coefficients as there are data. Test error, the sum of the three terms, is smallest at degree 5. Training error falls monotonically all the way, which is the optimism of Section 4.3 in action.
| degree d | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| \Bias^2 | .410 | .236 | .047 | .011 | .001 | .000 | .000 | .000 | .000 | .000 | .000 | .002 |
| \Var | .012 | .018 | .023 | .028 | .033 | .039 | .045 | .056 | .070 | .104 | .206 | .771 |
| test error | .512 | .344 | .160 | .128 | .124 | .129 | .135 | .146 | .160 | .194 | .297 | .863 |
| training error | .504 | .331 | .119 | .073 | .057 | .050 | .045 | .038 | .032 | .025 | .020 | .013 |
6.4The U-shaped curve
Figure 5 plots the same quantities against the degree. As flexibility grows, bias falls because the model can represent more of f, and variance rises because the model increasingly fits the noise of each particular sample. Their sum plus the noise floor is the famous U-shaped test-error curve. To the left of its minimum the model underfits; to the right it overfits. The dashed training-error curve keeps falling throughout, which is exactly why it cannot be used to choose the model.
6.5What changes with more data
Variance is a finite-sample phenomenon: with more data, every fitted model is pinned down more firmly. Figure 6 repeats the experiment (with fresh random draws) for n=15, 30, 60 and 120 points per training set. The variance of the degree-12 fit collapses from 0.66 to 0.039, 0.018 and 0.009, and the best achievable test error falls from 0.124 to 0.108, 0.099 and 0.095, approaching the noise floor of 0.09. In this example the best degree stays at 5 for every n, because degree 5 already has almost no bias; with a more complicated truth, more data would also move the optimum toward more flexible models.
Pause and think. Table 1 shows the bias of degree 12 (0.002) slightly above that of degree 8. Shouldn’t a more flexible model always have less bias?
Show the answer
Not exactly. Bias is measured for the whole procedure, including least squares on only 15 points. Very high-degree fits are numerically unstable near the ends of the interval, and their average does not converge perfectly to f there. Monotone bias is a tendency, not a theorem.