Thought Toys · Strategy & computation · Exhibit 60

The fit that memorizes instead of learns

A curve flexible enough to touch every point you gave it can still be a worse guess about everything you didn't. Past a point, more flexibility isn't learning the pattern — it's memorizing the noise.

18 noisy samples of a true curve, and the best-fit polynomial true curve fit

your turn — drag the degree past the sweet spot and watch the true-error curve turn upward

What you're seeing

The dashed curve is the real pattern generating the data — a plain sine wave. The 18 dots are noisy samples of it, and the solid curve is the best-fit polynomial of degree d: 1 is a straight line, 2 a parabola, and so on up to a curve wiggly enough to have twelve independent bends. Underneath, the second chart tracks two kinds of error as d climbs: training error — how far the fit sits from the 18 dots it was actually given, and true error — how far the fit sits from the real sine curve, checked at hundreds of points it never saw.

Training error can only ever fall as d rises — more flexibility can always hug the given points more closely, and by d=17 it would pass through all 18 exactly. True error tells a completely different story: it falls too, at first, because a low-degree line or parabola genuinely can't bend the way a sine wave does — that's real, honest bias. But past a point, roughly where d starts to exceed what the data can actually support, the two curves split. The fit keeps hugging the dots tighter, but the extra bends between them start tracking that particular batch of noise rather than the sine wave underneath — and true error turns and climbs, sometimes by orders of magnitude. Turn the noise dial down toward zero and try it: with nothing to memorize, the split disappears and more flexibility just keeps helping.

The rule, exactly. Fitting n points of degree-d least squares, training error is non-increasing in d for a fixed dataset, reaching (near) zero once d = n−1 (the unique interpolating polynomial). True error — measured against the real function on a dense grid — is not monotone: averaged over many independent noisy datasets at σ = 0.3 (n=18), it bottoms out around d* 3, roughly better there than at d=1 and roughly 2,000× better than at d=12 — and raising σ only ever pushes d* down, never up. Verified in node (improve/verify/60-overfitting.js): exact interpolation at d=n−1 with zero noise; training error non-increasing in d across eight seeds; the U-shape and its 8×/10× margins hold averaged over 80 independent datasets; and heavier noise never raises the optimal degree. Negative control: at σ=0, true error falls (weakly) monotonically all the way to machine precision by d=12 — no U-shape at all. It's the noise being memorized, not the flexibility itself, that makes a fit go bad.

Also in Strategy & computation: When the wire breaks, pick one →

All 23 in Strategy & computation
  1. 10The evolution of trust
  2. 23Sorting algorithms
  3. 24PageRank & the random surfer
  4. 25Huffman coding
  5. 26Dijkstra's shortest path
  6. 27Nash equilibria
  7. 33The learning-rate cliff
  8. 36A* pathfinding
  9. 37Braess's paradox
  10. 44Diffie–Hellman key exchange
  11. 45Preferential attachment
  12. 46Aliasing & the Nyquist limit
  13. 47The secretary problem
  14. 49Freeze too fast, stay stuck
  15. 51Cross one line, and its territory closes
  16. 56Catch one error, miss the next
  17. 57Why more processors stop helping
  18. 58Why a busy line explodes
  19. 59The set that's only sure when it says no
  20. 60The fit that memorizes instead of learns — you are here
  21. 61When the wire breaks, pick one
  22. 67Better at both, and still better off trading
  23. 69Everyone was consistent. The vote wasn't.

← the cabinet · Thought Toys — a cabinet of explorable explanations. Exhibit 60.