Overfitting and underfitting
A curve can match past examples closely and still miss new ones. Compare how a model learns a pattern, misses it, or memorises random bumps.
The pattern is more useful than every bump.
A pattern is a relationship that tends to repeat. Noise is variation that does not repeat reliably. A model learns from examples, so it can pick up the pattern, noise, or some of each.
Generalisation means making useful predictions on examples the model has not learned from. Lesson 5.5 introduced training and validation sets: training examples teach the model; held-back validation examples help us check how well its predictions carry over.
A prediction error is how far a prediction misses. Training error is the average miss on training examples; validation error is the average miss on held-back validation examples. Model flexibility describes how many different shapes a model can represent.
Sam wants to predict daily scoops sold from afternoon temperature. Sales tend to rise on warmer days, then level off on very hot days. A passing shower or local event may shift one day’s sales; those one-day bumps are noise.
Imagine Sam keeps eight past days for training and six different days for validation. The useful pattern is the broad rise and plateau, not the exact sales count on every individual day.
Underfitting misses the pattern.
Underfitting happens when a model is too limited to capture the main relationship in its examples. It tends to make large errors on both training and validation examples.
If Sam’s model predicts 63 scoops on every day, it ignores temperature. It is too simple for the rise and plateau, so it misses cool and warm days in both sets. A more flexible curve could represent that shape.
Outside this example, a one-size-fits-all jacket is like an underfitting model: its simple shape may not fit many people well.
Overfitting memorises bumps.
Overfitting happens when a model follows details in its training examples that do not carry over to new examples. It can have very low training error and much higher validation error.
A wiggly curve can pass through all eight training days, including a shower-day bump. If the wiggle swings away from the six validation days, the close training match was misleading. It memorised the training details instead of capturing only the pattern.
Think of an exam: memorising answers on one practice sheet may not help with new questions.
A good fit captures the trend.
A good fit captures the repeatable pattern without trying to match every noisy point. Its predictions tend to stay useful on held-back examples too. “Good” here means a useful balance for this data, not a guarantee about every future case.
A smoother curve follows the rise and plateau in Sam’s sales. It may miss a few noisy training points, but can predict the six held-back days better than a curve that chases each bump.
Learning the ideas behind exam questions is more likely to carry over than memorising one answer sheet, though no practice can cover every possible question.

Compare both errors to diagnose the fit.
Recall that training error measures average misses on training examples, while validation error measures misses on held-back examples. “Low” depends on the task, so compare the two errors as well as their size.
| What you see | What it may suggest |
|---|---|
| High training and validation errors | Underfitting: the main pattern may be missed. |
| Low, similar errors | A useful fit that may generalise to new examples. |
| Very low training, much higher validation error | Overfitting: training details may not carry over. |
As model flexibility increases, training error often falls. Validation error may fall at first, then rise if the model starts following training noise. These curves are a useful guide, not a rule that every real model follows exactly.

Try the curves on Sam’s days.
Use the controls in order: inspect the training view, reveal the validation days, then compare all three curve shapes and their average errors.
These six days are held out while each curve is fit. Because we compare curves using them, they guide a choice; they are not an untouched final test. In practice, reserve separate test data for a final check.
- Start on Too flexible (Overfit) with unseen days hidden—notice the 0.0 scoops training error.
- Click Show unseen validation days to reveal six new days the curve never saw.
- Switch between Too simple, Balanced, and Too flexible and compare both average errors.
On training days alone this looks like a perfect 0.0-scoop fit—turn on unseen validation days to see if it holds up.
Illustrative simulation: these temperatures, scoop counts, and curves are invented to demonstrate fitting behaviour, not measurements from a live model.
Check your understanding.
Take this with you.
A perfect training fit is not automatically best. Underfitting misses the pattern; overfitting follows training noise; a useful fit captures the pattern and carries over to unseen examples.
Compare training error with validation error. High errors on both can suggest underfitting, low and similar errors can suggest a good fit, and a wide gap can suggest overfitting.