Thought Toys · Computation & information · 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 Computation & information: When the wire breaks, pick one →

All 20 in Computation & information
  1. 101Noise sets a speed limit, not an accuracy limit.
  2. 111Any party of six hides a trio
  3. 120How one bit of ink makes a grey
  4. 125The ambulance that arrives sooner by going slower
  5. 131Every number is a sum of Fibonacci numbers
  6. 23Sorting algorithms
  7. 24PageRank & the random surfer
  8. 25Huffman coding
  9. 26Dijkstra's shortest path
  10. 33The learning-rate cliff
  11. 36A* pathfinding
  12. 44Diffie–Hellman key exchange
  13. 49Freeze too fast, stay stuck
  14. 56Catch one error, miss the next
  15. 57Why more processors stop helping
  16. 58Why a busy line explodes
  17. 59The set that's only sure when it says no
  18. 60The fit that memorizes instead of learns — you are here
  19. 61When the wire breaks, pick one
  20. 82Your computer can't hold one tenth

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