## glossary
What is Overfitting?
Overfitting happens when a machine learning model fits the training data too closely, capturing not only the real patterns but also the noise and quirks of that specific sample. The result is a model that performs very well in training and poorly on new data.
The most useful analogy is the student who memorizes the answers to last year's exam instead of understanding the subject: a perfect score on the practice test they have already seen, and a failing grade on the real one.
How to spot it
The telltale sign is the divergence between the error curves. While the training error keeps falling, the validation error plateaus and then starts to rise — the point where it turns is where the model stopped learning and started memorizing.
epoch train_error val_error
1 0.68 0.71
5 0.31 0.35
10 0.18 0.24 <- best point
20 0.07 0.29 <- validation gets worse
40 0.01 0.38 <- memorized the training set
# near-perfect training + poor validation = overfittingWhat causes it
- A model too complex for the amount of available data — spare parameters left over to memorize examples.
- Insufficient training data, or data that poorly represents the real variety.
- Training for too long, past the point where the model had already generalized.
- Data leakage — information from the test set influencing training, artificially inflating performance.
- Irrelevant features that offer noise for the model to latch onto.
Techniques to fight it
Each technique attacks the problem from a different angle:
- More data — the most effective solution when feasible; it makes memorization harder.
- L1 and L2 regularization — penalizes large coefficients, keeping the model simpler. The basis of Ridge and Lasso regression.
- Cross-validation — evaluates on multiple splits of the data, giving a more reliable estimate.
- Early stopping — halts training when the validation error stops improving.
- Dropout — in neural networks, randomly disables neurons during training, preventing rigid dependencies.
- Data augmentation — generates variations of existing data (rotation, cropping, noise) to broaden diversity.
The opposite extreme: underfitting
Fighting overfitting with excessive zeal leads to the inverse problem. In underfitting, the model is too simple to capture the patterns and performs poorly in both training and validation. The balance between the two is known as the bias-variance trade-off: simple models have high bias, complex models have high variance, and the goal is the middle ground. Regularization techniques applied to regression are detailed in types of linear regression.
## faq
Frequently asked questions
How do I know if my model is overfitting?
Compare performance in training and in validation. If the training error is very low and the validation error is significantly higher, the model is overfitting. A large and growing gap between the two curves across epochs is the clearest indicator.
Is overfitting always bad?
Yes, whenever the goal is to generalize to new data — which is practically always. An overfitted model is optimized for data that no longer matters.
Does adding more data always fix it?
It helps a lot, but it is not a silver bullet. If the new data comes from the same biased source, or if the model is excessively complex for the problem, overfitting can persist. It usually takes a combination of more data, regularization and model simplification.