Overfitting happens when a model fits the details of its training examples too closely, including coincidences and errors. It does well on what it already saw and worse on new data. The extreme case is memorizing, like someone who memorized the answers to an old exam and is lost when the questions change.
📚Thousands of examples→⚙️Tunes its numbers→🆕Tested on new data
Put it to the test
A question from the app. Pick an answer.
A model gets right what it studied but fails on similar new cases. What happened?
It is overfitting: it learned details of its examples that do not help on new cases. Memorizing the answers is the extreme case.
It usually makes it worse: more passes over the same examples fit it even more to them. More varied data and a separate test set help.
A model does not get tired: once training ends, its numbers stay fixed. It fails because it kept details of its examples that do not repeat in new cases.
Before training, some data is set aside that the model does not learn from: validation data, for decisions during training, and the test set, kept for the final evaluation. If it gets 99% right on its examples and 70% on the data set aside, that gap is the signal.
An example: a spam filter trained on few emails. By chance, several spam messages came on Tuesdays, and the model learns that "Tuesday" means spam. On the training emails it works perfectly; on next week's emails, it sends normal messages to spam.
How to avoid it
More and more varied data: if there is spam from every day, "Tuesday" stops looking like a clue. A simpler model: with less room to memorize, it has to stick to the general pattern. Stopping in time: it is measured on the validation data while it trains and stopped when it no longer improves there, even if it keeps climbing on the training data. The test set stays untouched until the end.
The opposite: underfitting
Underfitting is falling short: the model is too simple or trained too little, and it fails both on what it saw and on new data. Like someone who only read the back cover and does not even know the old exam's answers. Good machine learning looks for the middle ground between the two.
Common mistakes
"If it gets almost everything right in training, it is a good model." What matters is how it does on data it never saw. "More training passes will fix it." On the same examples, it usually memorizes them more. "My evals look good, so it generalizes." Only if the test cases were not part of what the model learned from.