The capacity dial — from too dumb to too eager
Twelve solid dots are the training set (a gentle curve plus noise). Six hollow dots are the test set — same truth, new samples, never shown to the model. Drag the degree slider: at 1 the model is too rigid to learn the shape (underfit); around 3 it captures the truth; past 9 it starts threading every noisy dot exactly — and the hollow dots drift away from the curve. Both error numbers are live.
Every drag re-solves the least-squares fit from scratch on the same 12 points. The wiggle you see at high degree is the model spending its extra capacity on noise.
The scissors — watch train and test split mid-training
Overfitting isn't only about model size — it happens over time. Here a flexible model trains step by step on scarce data while both losses are tracked. They fall together, then the scissors open: train keeps dropping, test turns around and climbs. The gold marker is the moment you should have stopped. Add more data and watch the scissors open later and less.
Genuine gradient descent on a degree-9 polynomial; the early-stopping marker is placed at the measured minimum of the test curve, after the run finishes.
The smoking gun — make it memorize pure nonsense
Skeptical that "low training error" can be completely meaningless? Do the famous experiment (Zhang et al., 2017, in miniature): press the shuffle button to randomly reassign every training answer, destroying all real structure. Then fit. The flexible model still drives training error to nearly zero — it's memorizing pure noise — while test error sits at "guessing" level. Same model, same optimizer, same zero training error, opposite meaning.
The shuffle genuinely permutes the y-values among the same x-positions each click — there is nothing left to learn, and the fit happens anyway.
Drown the noise — data is the strongest regularizer
Keep the dangerous degree-10 model, but feed it more. Drag the slider from 10 points to 200 and watch the same over-eager polynomial straighten out: with 10 points the noise is the dataset; with 200 points the noise averages away and even a crammer is forced to learn the pattern. Test error is measured live at every position.
Model capacity is frozen at degree 10 throughout — the only thing changing is evidence.
The pencil-weight penalty — and its own overdose
Can't shrink the model, can't buy data? Charge the model for complexity. Ridge regularization adds a fee proportional to the size of the coefficients, so wild wiggles have to pay rent. Drag λ up from zero: the curve calms, test error falls… then keep going and the fee gets so heavy the model can't afford the true pattern either. The U-curve on the right is measured from real fits at every λ.
Degree fixed at 12, data fixed at 14 points. The right-hand U is recomputed by refitting at 40 λ values when the page loads — your slider position is the gold dot on it.