Lesson 6: Overfitting and Generalisation: Why Models Memorise
A model that scores perfectly on its training data has not necessarily learned anything useful. It may have memorised the examples instead — storing their quirks and noise as if they were the pattern. This is overfitting, and it is the most common disappointment in machine learning: training loss falls beautifully, validation loss stalls and then rises, and the model fails on anything it has not seen before. The gap between training and validation performance is the clearest sign that memorisation has replaced learning.
Overfitting happens when a model has more capacity than the problem needs, or more freedom than the data can justify. A network with millions of weights can bend itself to fit every training example exactly, including the ones that are mislabelled or unusual. The data cannot argue back: the network is doing exactly what it was asked to do — reduce the training loss — and memorisation reduces it very well. The fault is not in the network but in how it was judged.
Generalisation Is the Real Goal
What we actually want is generalisation: good performance on new examples drawn from the same world as the training data. A model generalises when it has learned the pattern that is shared across examples, rather than the details that belong to individual ones. The validation set exists to measure exactly that. If training loss and validation loss fall together, the model is learning something real; when they split apart, it is memorising.
The simplest defences are about data and size. More training data makes memorisation harder, because there is too much to store and the shared pattern is the only thing that fits everything. A smaller network has less room to memorise, and can be forced to find the simpler explanation. Early stopping — halting training when the validation loss stops improving — is another cheap and effective defence: it simply refuses to let training continue into the memorisation phase.
A Worked Example of the Split
Imagine a worked example: you train a network to recognise handwritten digits, with 1,000 training images and 200 validation images. After a few epochs, training accuracy is 96% and validation accuracy is 94% — the two agree, so the model is learning. After many more epochs, training accuracy reaches 100% while validation accuracy has slipped to 88%. Nothing changed in the data; the network simply spent the extra epochs memorising the training images. The right response is to stop earlier, add more data, or use the regularisation methods of the next lessons — not to celebrate the 100%.
Keep this picture in mind whenever a result looks too good. A model is only as good as its performance on data it has never seen, and the honest test is always the held-out set. Everything in the next two lessons — regularisation, validation discipline, and building a network properly — exists to protect that one idea.
Memorisation Versus Understanding
There is a useful analogy for overfitting: a student who memorises past exam papers instead of learning the subject. Faced with the exact questions from those papers, the memoriser scores perfectly; faced with new questions on the same topic, they fail. A network does the same thing when it has the capacity to store its training examples and no reason not to. The training loss is the past paper; the validation set is the new exam. The analogy also explains why more data helps: with a thousand past papers to memorise, the student would have to learn the subject anyway, because memorising that much is harder than understanding it.
The analogy has limits, and knowing them matters. A human student can decide to understand; a network cannot — it simply follows the gradient downhill, and memorisation is often the shortest path down. That is why the defences against overfitting are structural rather than motivational: you limit capacity, add data, stop early, or regularise, because you cannot ask the network to try harder to understand. Your job as the practitioner is to shape the task so that the easy path downhill happens to be the one that generalises.
Key Terms
- Overfitting
- When a model memorises its training data instead of learning the shared pattern, so it fails on new examples.
- Generalisation
- How well a model performs on new, unseen examples.
- Capacity
- How much a model can fit; a larger network has more capacity and more room to overfit.
- Early stopping
- Halting training when validation performance stops improving, to avoid memorisation.
- Training accuracy
- Accuracy measured on the examples the model trained on.
- Validation accuracy
- Accuracy measured on held-out examples the model did not train on.
- Memorisation
- Storing individual training examples rather than learning the pattern behind them.
Discussion Questions
- Why does a model that gets 100% on its training data deserve suspicion rather than celebration?
- If you had to choose between more training data and a bigger network, which would help overfitting more? Why?
- Early stopping throws away training time. When might that be the wrong call?
Practice Questions
- What is the clearest sign of overfitting?
- Why can a very large network overfit more easily than a small one?
- In the worked example, training accuracy reached 100% while validation accuracy fell to 88%. What had the network done?
- What is early stopping?
- Why is the validation set a better judge than the training set?
Show answers
- Training loss keeps falling while validation loss stalls or rises. The growing gap shows the model is memorising rather than learning.
- It has more capacity — more weights to bend — so it can fit every training example exactly, including noise and mislabelled examples.
- It had memorised the training images. The extra epochs fitted the training set exactly instead of improving the shared pattern.
- Halting training when validation performance stops improving. It prevents the later epochs where memorisation takes over.
- Because it contains examples the model has never seen, so it measures generalisation — performance on new data — instead of memory.