Evaluating Models on Unseen Data
A high training score is necessary for a useful model only in the sense that a model which fails on training data is already in trouble. It is never sufficient on its own to establish generalization.
Why Training Scores Can Mislead
When people first train a machine learning model, they often judge it by how well it does on the examples it was trained on. If the predictions match the training data closely, it feels as though the model has learned something useful. That feeling can be wrong. The real goal of a model is different from matching the data it has already seen.
A very common misconception is that a model which performs perfectly on its training data is a good model. Under this belief, the best model is whichever one makes the fewest mistakes on the examples it studied. But a model is not built to repeat the past. It is built to make useful predictions on data that arrives later, data it has never seen.
Two models can have identical scores on the training examples and still behave very differently on new inputs. Only the new inputs reveal which model has learned the underlying relationship and which has simply stored what it was shown. This is why generalization, meaning performance on new, previously unseen data, is the central target.
Tracing Two Poor Models on Training Data
To make both failure modes visible, consider a tiny made-up dataset. Each training input is paired with a target value, and the targets follow a clear upward pattern, here $y = 2x + 1$. We compare two deliberately poor models. The first is too simple: it always predicts the same number, so it cannot follow the rising trend. The second is too rigid in the other direction: it simply stores the training pairs and has nothing to say about inputs it has never stored.
1 3 6 3
2 5 6 5
3 7 6 7
4 9 6 9
5 6 Nonetoo_simpleignores its input entirely and always returns 6- stored keeps the training pairs; memorizer looks them up and returns None for anything it never stored
- The loop compares each training input with its target, the constant answer, and the memorized answer
- The final line asks both models about input 5, which is not in the training data
Read the output carefully. On the four training inputs, the memorizer is perfect, matching every stored target. The too-simple model is wrong on every one of those inputs: its answer of 6 misses the targets 3, 5, 7, and 9 by 3, 1, 1, and 3. A constant cannot follow a rising pattern, so this model fails even on the data it was shown.
What Generalization Means
Generalization means performing well on new, previously unseen data. Training performance alone cannot show whether a model has achieved it, because a model can match its training examples for reasons that have nothing to do with the underlying relationship.
The memorizer in the previous example illustrates the gap. It is perfect on every training input, yet it has no answer for input 5. Its training score tells you it stored the examples correctly; it says nothing about whether it learned the pattern that produced them. The too-simple model shows the opposite gap: its training score is poor, so the failure is visible before any new data is involved.
A high training score is necessary for a useful model only in the sense that a model which fails on training data is already in trouble. It is never sufficient on its own to establish generalization.
Underfitting: Failing Before New Data Appears
Underfitting describes a model that is too simple to capture the variations present in the training data. Its key feature is that the failure shows up before any new data is involved. If the training examples clearly rise and fall in a way the model ignores, its predictions will be wrong on those training examples too. The model has not learned enough to describe what it was shown.
Overfitting: Looking Strong on Familiar Examples
Overfitting describes a model that focuses too much on the training data and cannot generalize to new data, even when it looks strong on training examples. Overfitting is the reverse of underfitting in one important way: an overfitted model often looks excellent when you check it against its training examples, because it has adapted to those examples closely.
The trouble appears when the model meets inputs it did not study. The memorizer is the clearest case: it reproduces every training target exactly, but on input 5 it has no answer at all. An overfitted model's answers on unfamiliar inputs can be far from useful, even though its training record looks flawless.
Model Complexity as the Connecting Thread
The two failures sit at opposite ends of a range of model complexity, and they are told apart by where they show their weakness. A model that is too simple for the data tends toward underfitting. A model that is too complex for the data and fixed to the training examples tends toward overfitting. The goal is a model whose complexity matches the problem well enough to capture the real pattern without memorizing noise.
Many algorithms have settings that control complexity, and choosing the right parameter values matters for good performance. Model selection is therefore not a matter of picking a famous algorithm and trusting it. Blindly applying an algorithm without understanding its assumptions and the meaning of its parameter settings will rarely produce an accurate model.
Holding Out Examples the Model Never Sees
Because generalization is measured on new data, an evaluation has to include inputs that the model did not study during training. The idea is to split the available examples so that some are used to fit the model and others are kept aside. The model is then scored on the set-aside examples, which it never saw while learning.
The held-out examples play the role that input 5 played in the tracing example. Only a score on examples the model never studied can reveal whether it generalizes, and only that score can show whether a model failed by missing the pattern or by memorizing it.
Tracing the Symptoms on New Input
Return to the two models and ask what each one does when the input is new. Before reading on, predict the answers for input 5.
What do you think happens?
What does the constant model answer for input 5, and what does the memorizer answer?
Reveal answer
The constant model answers 6, and the memorizer returns None because it never stored input 5.
The constant ignores its input, so it answers 6 for every x. The memorizer can only return values for inputs it stored, so it has nothing for 5.
Diagnosing which failure a model shows
A model scores well on its training examples but gives no useful answer on new inputs. Which failure mode does it show, and what is the symptom?
- 1Check training behavior
The model matches its training examples closely, so it does not fail there. This rules out underfitting, which shows up on training data.
- 2Check behavior on new inputs
On new inputs the model cannot give a reliable answer, or its answers are far off. This is the gap that defines overfitting.
- 3Name the failure
The model has memorized its training examples instead of learning the pattern behind them. The symptom is excellent training performance paired with poor performance on unseen data.
The model shows overfitting. The memorizer in the example behaves this way: perfect on training inputs, no answer on input 5.
The reverse case is diagnosed the same way. A model that is poor on its training examples has shown underfitting before any new data arrives, and adding new inputs to the evaluation will not change that conclusion.
Mistakes When Judging a Model
Common mistake Treating a perfect training score as proof of a good model
What it looks likeThe memorizer matches all four training targets exactly, so it looks flawless on that evidence.
Why it failsA model is built to make useful predictions on data that arrives later. Matching examples it has already stored does not show that it learned the pattern.
Do this insteadJudge the model on inputs it did not see during training before deciding it works.
Common mistake Assuming a model that fails on training data is fine on new data
What it looks likeThe constant model misses the training targets 3, 5, 7, and 9 by 3, 1, 1, and 3.
Why it failsUnderfitting shows up before any new data is involved, so poor training performance is already evidence of a problem.
Do this insteadRead training errors as a first diagnostic, then confirm the pattern with unseen data.
Common mistake Picking an algorithm and trusting it without checking its settings
Why it failsMany algorithms have parameters that control complexity, and their assumptions shape the result.
Do this insteadUnderstand the assumptions and the meaning of the parameter settings before judging the model.
Practice Diagnosing a Model
A model's predictions on its training examples are far from the targets, and it also performs poorly on new inputs. Which failure mode does it show, and what is the evidence? Then describe what a model with the opposite pattern would look like.
Hints
- Ask first whether the failure appears on training data or only on unseen data.
- Underfitting shows up before any new data is involved; overfitting shows up on unseen inputs despite strong training results.
A model returns the same value for every input, and that value is wrong on each training example. Explain why this is underfitting rather than overfitting, using the training examples as evidence.
Hints
- Consider what the model does with its input.
- Think about what the training data alone reveals.
Key Takeaways
- Generalization means performing well on new, previously unseen data, and training performance alone cannot show whether a model has achieved it.
- Underfitting is a model too simple to capture the variations in the training data, so it fails even on training examples.
- Overfitting is a model that focuses too much on the training data; it can look strong on training examples yet fail to generalize.
- Model complexity connects both failures, so choosing appropriate parameter settings and understanding a model's assumptions are essential to avoid them.