Diagnosing Overfitting and Underfitting and Improving Models
This lesson explains how comparing performance on training data with performance on held-out data shows whether a model is too simple, too complex or about right, and what to do next. A model is useful only if it performs well on data it has never seen.
Learning outcomes
After completing this lesson, you will be able to:
- Explain why data is split into training, validation and test sets.
- Diagnose underfitting and overfitting from training and test results.
- Identify the actions that improve a model's performance.
Splitting the data
Data used to develop a model is split into three sets, so that the final measure of performance comes from data the model has never seen. The training set is used to fit the model's parameters. The validation set is used during development to choose hyperparameters and compare candidate models. The test set is used once, at the end, to estimate how the model will perform on new data; if it were used earlier, the estimate would be too optimistic. The following table summarises the three sets.
| Set | Used for |
|---|---|
| Training set | Fitting the model's parameters |
| Validation set | Choosing hyperparameters and comparing models |
| Test set | A final, unbiased estimate of performance on new data |
Cross-validation rotates which part of the data is held out, giving a more reliable estimate when data is limited.
Three data sets
Diagnosing fit
Comparing a model's results on training data and on test data shows what is wrong with it. If it performs poorly on both, it is underfitting: it is too simple to capture the pattern, which is high bias. The remedies make it more capable: a more complex model, better features, longer training or less regularisation, which is the set of techniques that keep a model simple.
If it performs excellently on training data but poorly on test data, it is overfitting: it has memorised the training examples instead of learning the general pattern, which is high variance. The remedies help it generalise: more or more varied data, a simpler model, regularisation, stopping training early, dropout, or data augmentation, which creates extra training examples by altering existing ones. A model that performs well on both fits well, and it should then be monitored in production for drift. The following table summarises the diagnosis.
| Symptom | Diagnosis | Remedies |
|---|---|---|
| Poor on training and test data | Underfitting (high bias) | More complex model, better features, train longer, less regularisation |
| Excellent on training data, poor on test data | Overfitting (high variance) | More or more diverse data, simpler model, regularisation, early stopping, dropout, data augmentation |
| Good on both | Good fit | Monitor in production for drift |
The following diagram compares training and test results for each diagnosis.

Which problem does it fix?
Improving performance
The performance of a model can be improved in several ways. The following list describes the principal methods.
- Better data usually improves a model more than a better algorithm does: more examples, fewer label errors, balanced classes.
- Feature engineering: create informative inputs, such as days since last purchase instead of a raw date.
- Hyperparameter tuning: SageMaker AI automatic model tuning searches settings such as learning rate and tree depth for the best validation score.
- Transfer learning: start from a pre-trained model and fine-tune it, which needs far less data.
What would help most?
A model scores 99% accuracy on its training data but 70% on new data. Which action is most likely to help?
The gap means overfitting. Adding more diverse training data or regularisation (or reducing model complexity) helps. Training for more epochs or adding model complexity would make it worse.
A model scores very well on training data but poorly on test data. What is the problem?
Show answer
Overfitting: the model memorised the training data instead of learning general patterns. More data, regularisation or a simpler model can help.
Exam Tips
Remember for the exam
- Training, validation and test sets serve different purposes; never tune on the test set.
- Underfitting: poor results on all data. Overfitting: strong results on training data, poor results on new data.
- Fix overfitting with more data, regularisation, early stopping or a simpler model.
- Fix underfitting with a more complex model or better features.
- SageMaker automatic model tuning optimises hyperparameters.