The Generalisation Problem
The goal of a neural network isn't to perform well on training data — it's to perform well on new data it hasn't seen before. A model that achieves 99% accuracy on training images but 60% on new images has learned nothing useful. It has memorised the training set.
This gap between training performance and real-world performance is overfitting. It's the central challenge of machine learning.
Underfitting, Good Fit, Overfitting
The model is too simple to capture the pattern. Both training and validation accuracy are low. The model hasn't learned enough — add capacity (more layers/neurons) or train longer.
Training and validation accuracy are both high and close to each other. The model has learned the underlying pattern without memorising noise. This is the target.
Training accuracy is high; validation accuracy is noticeably lower. The gap grows over time as training continues. The model has started memorising training-specific noise.
Plot training vs. validation loss over epochs. If they diverge — training keeps falling while validation plateaus or rises — you're overfitting. Always monitor both.
Dropout
Dropout is a regularisation technique that randomly "switches off" a fraction of neurons during each training step. A neuron that's dropped out produces no output and receives no gradient update for that step.
With a dropout rate of 0.5, each neuron has a 50% chance of being ignored during any given training pass. This sounds destructive — but it's extraordinarily effective.
Why it works
Dropout forces the network to learn redundant representations. No single neuron can be relied upon — it might be dropped at any moment. So multiple neurons must learn to represent the same feature independently. The result is a network that's robust to the absence of individual neurons.
It also acts as training an ensemble of many different networks simultaneously. Each training step uses a different random subset of neurons — a different "sub-network." The final model is effectively an average of all these sub-networks, which is much more generalised than any single one.
Batch Normalisation
Batch Normalisation (BatchNorm) normalises the output of each layer to have zero mean and unit variance — computed across the current mini-batch. Then it applies learnable scale and shift parameters, letting the network adjust the normalisation if needed.
What it solves
- Internal covariate shift: As earlier layers update their weights, the distribution of inputs to later layers keeps changing. BatchNorm stabilises this — later layers always receive input with the same scale.
- Allows higher learning rates: Without BatchNorm, high learning rates cause exploding or vanishing gradients. BatchNorm keeps activations in a stable range, making training more aggressive and faster.
- Mild regularisation effect: Because normalisation is computed per-batch (which varies), it introduces slight noise — acting as a weak form of regularisation on top of its primary role.
Other Regularisation Techniques
Early Stopping
Monitor validation loss during training. When it stops improving for a specified number of epochs (the "patience"), halt training and restore the weights from the best epoch. Simple and extremely effective — it prevents the network from memorising noise in later epochs when training loss is still falling.
Data Augmentation
Artificially increase the diversity of training data by applying random transformations: flips, rotations, brightness changes, small crops. The model sees more variation without collecting new data. Highly effective for image tasks.
L2 Regularisation (Weight Decay)
Add a penalty to the loss function proportional to the square of each weight's magnitude. Large weights are penalised, pushing the model toward smaller, more evenly distributed weights — less likely to overfit to specific training examples.
All four models used Dropout (rates 0.3–0.5) and Batch Normalisation after each dense layer. Early stopping with patience=5 halted training when validation loss plateaued. The effect was measurable: ANN2 without these techniques showed training accuracy of ~85% but validation accuracy of 77% — a 8-point gap signalling overfitting. With regularisation, the CNN2 final model showed a training/validation gap of under 2 points at 92.22% validation accuracy. See Chapter 5 — Regularisation →