seegongsik
AI

What is overfitting

Say a friend memorizes every answer in the workbook the night before an exam. When the very same questions come up, the friend gets them all right. But when a question appears with only the numbers slightly changed, everything collapses, because the friend memorized answers without understanding the principle. Machine learning has exactly the same trap. If a model memorizes its training data wholesale, it scores 100 on the questions it has seen but gets unfamiliar ones wrong. This is called overfitting.

01

Memorize everything and the training score is perfect

Here are some scattered points. The model's job is to find a smooth curve that captures the trend underlying them. But get greedy, and you can bend the curve into wiggles so that it passes through every single point.
Then all the training points sit on the curve, and the training score is a flat 100. It looks perfect, but in fact it has simply memorized where the points are.

smooth trend curve: it does not memorize the points
training accuracy: ~70%

Tap the button to switch on the wiggly curve that memorizes every point. Since it passes through them all, training accuracy becomes 100 percent.

The curve passed exactly through every point, and the training score became 100. That feels good, but you must not stop here. Real data almost always contains chance wobbles that crept in during measurement, in other words, noise.
A curve that passes through every point has followed not only the real trend but this noise as well. Why memorizing is a problem shows up the moment you add a new point.

02

When new data arrives, it collapses

The real test of a memorizing curve is a new point it has never seen. A new point comes from the same trend as the training points, so a curve that caught the trend well should land reasonably close to it.
But the memorizing curve swings wildly between the training points, so near a new point it points to a completely wrong height. It scores 100 on the questions it has seen but misses badly on new ones.

● training pt● new pt
Tap a hollow circle to drop in a new point
0 / 6

Tap a hollow circle to add a new point. The memorizing curve misses badly at that spot, showing that it is weak on data it has not seen.

At the new point, the curve missed by a long way. So perfect on the training points, it is helpless in front of a point it has not seen. That is what overfitting really is.
It is just like the friend who memorized answers collapsing at a question with changed numbers. So what we really want to know is not the training score but the score on data the model has never seen. The ability to do well even on unseen data is called generalization.

03

Splitting into training, validation, and test

To measure skill on unseen data, part of the data has to be set aside and hidden in advance. So the data you have is split into three. Most of it is used as training data for the model to learn from, and part is kept as validation data to check partway through whether learning is on track.
The remaining test data is left untouched until the very end and looked at only once. Only then does the scoring imitate a truly new exam.

train0
validation0
test0
Tap points to sort into the three bins

Tap the points to sort them into the training, validation, and test bins. Once all three are filled, you are ready to evaluate on test data the model has not seen.

The data has been split into three groups. The key is never to show the test data during training; if you work through the exam questions in advance, it is no longer an exam.
Validation data is also used to decide when to stop training. If the training loss keeps falling while the validation loss starts to rise again, memorizing has begun, so training is stopped. This is called early stopping.

04

Neither too simple nor too complex

Now let's compare three models. A model that is too simple tries to settle everything with one straight line and cannot follow the curve the points trace. This is underfitting, a state of having learned too little.
A model that is too complex memorizes every point and is weak on new data. The well-fitted model in between gently captures the pattern running through the whole, not each individual point.

Tap the three models to compare

Tap the three models in turn to compare them. The too-simple model fits poorly, the too-complex one memorizes and wobbles, and only the well-fitted model also does well on new data.

The difference between the three models was clear at a glance. Too simple, and the pattern is missed; too complex, and it memorizes and wobbles. Only the well-fitted model did evenly well, on both the training data and unseen data.
Good learning is not about pushing the training score up to 100 but about doing reliably well on data the model has never seen. To prevent overfitting, people also gather more data or add a penalty that keeps weights from growing too large.

05

Summary

To sum up: a wiggly curve that memorized every point scores 100 only on training and is weak on new points. That is overfitting. Real understanding means catching the pattern that runs through the whole.
So the data is split into training, validation, and test, and skill is measured on unseen data. A well-fitted model that is neither too simple nor too complex generalizes best.

Tap the key points in order to review

Tap the key points in order to review. (memorize everything and only training scores 100 → weak on new data → split into training, validation, and test → measure real skill on unseen data)

Now you know the difference between memorizing and real understanding. A high training score does not make a model good; what matters is not being thrown off by data it has never seen.
But to catch patterns well, above all the data fed into the model has to be good. Which data you collect, and which features in it you choose to feed in, changes the result a great deal. The next lesson, on data and features, takes this up.

In one lineOverfitting is when a model memorizes its training data and becomes weak on new data. A wiggly curve that passes through every point scores 100 on training, but because it has followed even the noise in the data, it misses wildly when a new point comes along. Real understanding means catching the pattern that runs through the whole, not each individual point. So the data is split into three: training data to learn from, validation data to check progress along the way, and test data kept hidden until the end and looked at only once. A model that is too simple cannot catch the pattern (underfitting), and one that is too complex memorizes (overfitting). The well-fitted model in between generalizes best, and gathering more data or using early stopping can reduce overfitting.
← AI
Was this helpful? Support seegongsik