Lesson 2.3 · 8 min read · about 50 min to master at a very slow pace

Underfitting and Overfitting

Too simple and a model misses the pattern; too flexible and it memorises noise. How to recognise each from training and validation errors, and what to do about it.

Not startedJump to quiz

Three fits to the same data

Underfit: a straight line misses the curve.
Good fit: follows the real pattern, ignores the noise.
Overfit: a degree-7 polynomial hits every point and wiggles wildly between them.

The overfit curve has zero training error: it passes through every point. Yet between and beyond the points it is wild, so its predictions for new data are poor.

The diagnosis table

Training errorError on unseen dataStory
UnderfittingHighHighModel too simple to capture the real pattern (high bias)
Good fitLow-ishSimilar, lowCaptures repeatable structure
OverfittingVery lowMuch higherFits noise and quirks of this sample (high variance)

The U-shaped curve

012312345678910model complexity (e.g. polynomial degree)errorunderfittingoverfittingsweet spot
Training errorError on unseen data
As complexity grows, training error only goes down. Error on new data first falls, then rises. Choosing complexity, or later the penalty λ, means choosing a point on this axis.

What to do

If you see...Try
UnderfittingA more flexible model, better features (e.g. , interactions), less regularisation
OverfittingMore training data, a simpler model, fewer features, regularisation (Section 5), cross-validation to tune complexity

Training error can't choose complexity

Training error always prefers the most complex model: a degree-10 polynomial always fits the training data at least as well as a degree-1 line. Use validation data or cross-validation instead.

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

Going deeperHow do I read training, validation and test results together?
  • Training high, validation low → possible overfitting.
  • Training and validation high, test low → possible distribution shift, a preprocessing inconsistency, or another evaluation problem (see lesson 2.4).
  • All three low → possible underfitting.

"High" and "low" here refer to performance (accuracy), not error.

Cheatsheet

Diagnose from errors

Train low, val high → overfit. Both high → underfit. Train & val good, test bad → shift / leakage / evaluation issue.

Training error picks complexity

Wrong: choose the model with the lowest training error. Right: choose on validation data or by CV.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1interpretTraining error is 2% and validation error is 28%. What's the most likely diagnosis?
Q2interpretTraining error is 35% and validation error is 36%. What's the diagnosis, and what might help?
Q3conceptWhy can't training error be used to choose between a degree-1 and a degree-10 polynomial?
Q4diagnoseA model overfits. Which of these changes would make it WORSE?
Q5interpretAs model complexity increases from very simple to very flexible, what typically happens?