Lesson
The theory — Overfitting: Fitting Well and Predicting Badly
Overfitting is a model describing the noise in the sample it was fitted to. Fit a polynomial of degree d through n noisy points and the training error falls for every extra degree, because each one buys another way to bend towards the points you already have; at d = n − 1 the curve passes through all of them exactly and the fit is perfect and worthless. The error that matters is the one on data the fit has never seen.
What each symbol means
d- the degree of the polynomial, the model's freedom to bend
σ- the noise the points were drawn with, which no model can predict
- Assumes
- That the noise is independent from point to point and the underlying curve does not move. Where the errors are correlated — a sensor drifting, a market regime — held-out data is not independent of the training data either, and every number on this page becomes optimistic rather than honest.
Problem solved in full
-
You have heard that more data lets you use a bigger model. Find out when that is true and when it is not, using the two truths where the answer differs. Start with the Straight truth preset and the The true model, too little data preset, and compare what the sample-size slider does to each.
-
Take the straight line first. Set the true function to Straight, the noise to 0.6, and walk the sample size across its whole range. The degree with the lowest true error sits at 1 for eight of the eleven sizes and at 2 for the other three, and it never goes higher than 2 or lower than 1. There is no trend in it — the twos land at 15, 20 and 50 points, not at the large end. More data buys no degrees here at all.
-
Now the cubic, which is where the slogan earns its keep. Set the true function to Cubic, the noise to 0.6, the split to 70%, and the sample size to 10. Seven points to train on. The true error at degree 3 is 0.7297 and at degree 1 it is 0.6107, so a straight line beats the correct model by a clear margin.
-
Read that again, because it is the surprising part: the data really was generated by a cubic, and fitting a cubic is the wrong thing to do. Four coefficients estimated from seven noisy points are so badly pinned down that the error they carry is larger than the curvature they capture.
-
Leave everything else and drag the sample size to 40. Twenty-eight training points now. Degree 3 gives 0.6496 and degree 1 gives 0.6616, so the cubic has moved ahead and the lowest-true-error degree is 3.
-
The two cases differ in one respect. For the straight line, degree 1 already contains the truth exactly, so no amount of data creates a reason to add a coefficient — there is nothing left for it to explain. For the cubic at ten points, degree 3 also contains the truth, and the sample is too small to locate it.
Answer
More data does not buy you a bigger model. It buys you the ability to afford the model you already needed. The condition is whether your current model class is missing something real: if it is, more data eventually lets you reach for the missing piece, and if it is not, more data changes nothing about the right complexity. That is why the straight-line truth sits at degree 1 from ten points to a hundred and twenty, while the cubic at high noise moves from 1 to 3 somewhere between ten points and forty. And the movement is not tidy — the seven sizes from 10 to 60 give 1, 1, 1, 4, 1, 3, 3, which is a trend with sampling variation on top rather than a staircase, because every sample size draws its own sample. A single run at a single size cannot tell you which of those two things you are looking at, which is the same lesson the two triangles under the error panel keep making.
-
Learning path
Fitting a line to data
References (3)
- Why a high-degree polynomial through evenly spaced points swings wildly between them — the effect the top panel shows at degree 11 and above: C. Runge, “Über empirische Funktionen und die Interpolation zwischen äquidistanten Ordinaten.” Zeitschrift für Mathematik und Physik 46, 224–243, 1901.
- The origin of the fix this page argues for but does not implement — averaging several splits instead of trusting one: M. Stone, “Cross-Validatory Choice and Assessment of Statistical Predictions.” Journal of the Royal Statistical Society Series B 36(2), 111–133, 1974.
- The standard treatment of everything on this page — the bias-variance decomposition, the shape of a test-error curve, and why a single split is a noisy estimate of it: T. Hastie, R. Tibshirani and J. Friedman, The Elements of Statistical Learning. Springer, 2009.