Why does the wiggly line that hits every dot predict worse than the straight one?
Lesson 18.3 · The Line That Wiggles Through Everything
Felix
The wiggle hits every training dot. The wiggle is terrible.
Felix gives his model more freedom, and the line starts bending to pass through every training dot.
Training error drops to zero. Then he checks the hidden dots, and the wiggly line misses them by a mile.
The straight line, which missed a few training dots, gets the hidden ones close. Felix is offended on the wiggle’s behalf.
The short answer
Because the training dots have noise in them, one kid who slept badly, one who guessed well, and the wiggle learned all of it as if it were real. The straight line ignored the noise and kept the pattern. On new dots, the pattern is all that repeats. Felix forgives the straight line.
Try it yourself
Slide from a straight line to a wild squiggle. Watch training error fall while the error on hidden dots climbs.
Training error: 0.4 · Test error: 0.6
What you just did has a name
Overfitting
Overfitting is when a model fits its training examples so closely that it learns their noise and coincidences, not just the pattern.
Training error drops, test error rises.
The cure is usually less freedom: a simpler model, more data, or stopping training earlier.
A few more things
The U-shaped curve
As the model gets more flexible, test error falls at first (it can finally capture the pattern), bottoms out, then climbs (it starts capturing noise). The bottom of that U is the model you want. Training error never tells you where it is.
Underfitting is the other ditch
A model too simple to capture the pattern misses on both training and test data. A flat line through curved data. The fix is more freedom, not less. The test score tells you which ditch you’re in.
Ashley’s model memorized #14
One video with a shocked face got 38,000 views. A flexible model on sixteen rows learns “shocked face means 38,000.” It’s the wiggle, in real life, and it’s why her next three predictions are absurd.
Go deeper
The longer version, if you want it.
Bias, variance, and regularization
The two ditches have names. A model too simple has high bias: it’s systematically wrong in the same way everywhere. A model too flexible has high variance: retrain it on a slightly different sample and it changes wildly, because it was fitting noise. Every model choice is a trade between them, and the U-shaped test curve is that trade drawn out.
Regularization is the family of tricks that lean a flexible model toward simplicity: penalizing big weights, dropping random pieces during training, stopping early when the validation score stops improving. Nearly every modern model uses several at once. They exist because, left alone, a big model will always take the wiggle.
Quick check
A model that predicts pizza delivery times is 30 seconds off on its training deliveries and 12 minutes off on new ones. Which fix makes sense?
Let’s take it slower
Picture a tailor who fits a jacket so exactly to one photo of you that it copies the wrinkle in your shirt that day. Fits the photo perfectly. Fits you badly tomorrow. That’s overfitting. Every set of training examples has one-off wrinkles in it, and a model with enough freedom will sew them in as if they were your shape. The tell is easy: near-perfect on the data it studied, wobbly on anything new. The fix is to give the tailor fewer pins, more photos, or a signal to stop sooner.
More examples
The stock tip that fit history
Someone finds a rule: the market goes up whenever a certain team wins in a certain month. It matches 20 years of history exactly. It also predicts nothing, because it was tuned to coincidences that already happened and won’t repeat.
The keyboard that knows one friend
A keyboard app learns from your texts to one friend and starts suggesting their inside jokes to everyone, including your boss. It fit your last hundred messages too well. The pattern that repeats is your grammar, not that one friend’s nickname.
Back to the question
So why does the wiggle predict worse?
Show the answer
Because the training dots have noise in them, one kid who slept badly, one who guessed well, and the wiggle learned all of it as if it were real. The straight line ignored the noise and kept the pattern. On new dots, the pattern is all that repeats. Felix forgives the straight line.
One last question
Felix reads his error numbers. Trust his conclusions?
“Training error is zero, so the model is perfect.”
“Test error went up when I made the model bendier, so it started overfitting.”
“Both errors are high, so I should make the model simpler.”
Talk Card
Talk Card · 18.3
A line that wiggles through every training dot looks perfect and predicts badly, because it learned the noise. Overfitting is memorizing with extra steps.
Data to AI · pettigrewlab.com/learn
