Lesson 2.4 · 7 min read · about 50 min to master at a very slow pace
Generalisation and the Generalisation Gap
Generalisation is performing well on new data. The generalisation gap is how much worse a model does there than on its training data. What makes the gap grow or shrink, and what to do when test scores disappoint.
Definition
Generalisation is the ability of a fitted model to perform well on new observations from the same population. The generalisation gap measures how far training performance overstates real performance:
The true gap can't be computed, because needs the unknown population. We estimate it by comparing training error with error on held-out data.
What affects the gap
| Factor | Effect on the gap |
|---|---|
| Model complexity / number of parameters | More flexible → bigger gap |
| Training-set size | More representative data → smaller gap (it tends to 0 as ) |
| Regularisation / algorithmic stability | Constraining the model → smaller gap |
| Noise in the data | Noisier → easier to "fit the noise" → bigger gap |
When the test score disappoints
Scenario
Validation accuracy is 96%, but the final test accuracy is only 79%. What now?
Possible causes: overfitting to the validation set through many rounds of selection; distribution shift (the test data differ from training and validation, e.g. collected later or elsewhere); preprocessing applied inconsistently to the test set; or an evaluation bug.
Actions: investigate the cause; improve the model using only training and validation data; then get a fresh, independent test set for a final honest estimate. Don't keep tuning against the same test set: that would leak it (lesson 2.8).
Big idea
A small gap is good news only if both errors are low. A model can have a tiny gap and still be useless (underfitting: both errors high).
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 deeperValidation accuracy is 96% but test accuracy is 79%. What should I do?
First, investigate rather than tweak. Likely causes are overfitting (often to the validation set itself, after trying many models), distribution shift between the validation and test data, preprocessing inconsistencies (e.g. the test set was scaled differently), or an evaluation problem.
Then improve the model using only the training and validation data, and evaluate the final version on a fresh independent test set. If you keep adjusting until the old test score goes up, that test set has become a validation set and its score is no longer an honest estimate.
Cheatsheet
Generalisation gap drivers
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.