Sub topic 1
What It Means for a Model to Generalise
Prerequisites
Assume you know Python and NumPy, supervised learning, loss functions, and the basic fit and predict workflow in scikit-learn.
Generalisation
A model generalises when it makes useful predictions on examples it has not seen during training. Training error measures mistakes on examples used to fit the model. Generalisation error measures mistakes on new examples from the same real-world process.
A low training error is not enough. The model's purpose is to perform well beyond its training data.
Model capacity: how flexible a model is
Model capacity is how much complexity a model can represent. A linear model has limited capacity. A high-degree polynomial or a large neural network has more capacity.
Higher capacity can capture real patterns, but it can also capture random noise. Lower capacity may miss important patterns. The useful level depends on the amount and quality of data.
Train, validation, and test sets
Split the available data by purpose:
| Set | Used for | Used during model selection? |
|---|---|---|
| Training | Fit parameters | Yes |
| Validation | Compare models and tune settings | Yes |
| Test | Estimate final performance | No |
Use the validation set while choosing model capacity or other hyperparameters. A hyperparameter is a setting chosen before training, such as polynomial degree. Keep the test set untouched until the final evaluation. Reusing it for decisions makes its score optimistic.
Underfitting: when the model is too simple
Underfitting occurs when a model cannot represent the underlying pattern. It usually has high training error and high validation error. Increasing capacity, adding useful features, or reducing excessive constraints may help.
Overfitting: when the model memorises noise
Overfitting occurs when a model fits accidental details in the training examples. It usually has low training error but much higher validation error. The gap between these errors is a warning sign.
You can reduce overfitting by using a simpler model, collecting more data, or applying methods such as regularisation. Learning curves, which show error as training progresses or data increases, help reveal these patterns.
Exercise
A model has training mean squared error 0.02 and validation mean squared error 0.80. Is this more likely underfitting or overfitting?
Show answer
Overfitting. The very low training error and much higher validation error show that the model learned training-specific noise.