DEMO by Michele di Nuzzo
Overfitting
MDN · LAB
OVERFITTING
- Degree
- model complexity
- Points
- how much training data
- λ ridge
- regularisation
- New data / Test data / True function
- what to show
A model has to work on data it has never seen. Here a polynomial learns from a few noisy points (filled dots); the small circles are test data, which the model does not see during training.
At low degree the model is too rigid and wrong everywhere (underfitting). Raising the degree always lowers the training error, but at some point the test error goes back up: the polynomial is learning the noise too (overfitting). The chart shows both curves: the best model is where the test error is lowest, not the training error.
Things to try
- Push the degree to the maximum with 12 points: the polynomial goes through almost every point and goes wild in between.
- Now add more points: with more data, the same degree is far less wrong.
- Or raise λ: ridge regularisation “calms down” the coefficients and reduces overfitting.
The demo is a single HTML file: download it and use it offline, even without an internet connection. Licence: CC BY-NC 4.0 — you may share it, crediting the author and this page, but not for commercial purposes.