Training and Test Sets
The trouble is that the training score alone cannot tell us whether the hope is justified in a particular case.
A Perfect Score That Proves Less Than It Seems
Imagine a model that gets every single training example right. It feels like a success, and it is tempting to call the job finished. In supervised learning, that feeling is misleading. A model exists to make predictions about cases it has never seen, and a perfect score on the cases it already studied says little about that goal.
The belief behind the temptation goes like this: if a model is 100 percent accurate on the training set, it will also work well on new data. The belief feels reasonable because we normally build a model so that it predicts the training data accurately, and we hope that accuracy carries over. That hope is often justified when the training data and the new data have enough in common. The trouble is that the training score alone cannot tell us whether the hope is justified in a particular case. This article shows how to tell the difference.
Splitting Data Into Training and Test Sets
The practical response to the problem is to keep some data out of training. The data we have is divided into two parts. The training set is the part the model learns from. The test set is held back, so the model never sees it during learning. The test set plays the role of unseen data, which lets us measure performance on examples the model has not been shown.
The diagram shows the flow. The model learns only from the training side. The test side waits until evaluation, where the model's predictions are compared with answers it has not seen. Only the test side can tell us whether the model's behavior carries over beyond the examples it studied.
Tracing a Memorizing Model
To see the problem in action, consider a model that does nothing clever. It stores each training customer's age together with the answer. When asked about an age it does not recognize, it simply says no. Before reading on, make a prediction about this model's score on the training data.
What do you think happens?
What would this memorizing model score on the training data?
Reveal answer
A perfect score on the training data.
The model stores each training customer's age with the answer, so it reproduces every training answer exactly. Its failure only appears on ages it does not recognize, which is where the training data says nothing.
4 of 4 correct on training data
no- The training pairs are made up for this example; they are not from the source table.
- memory is a lookup from each known age to its answer.
memory.get(age, "no")returns the stored answer for a known age and the default "no" for any other age.
Scoring the Memorizer on Old and New Customers
The memorizer is evaluated first on the training customers, then on a customer whose age it never saw during training (age 60).
- 1Score on the training data
Each training age is found in the stored lookup, so each answer is reproduced exactly. The score is 4 of 4, which is 100 percent.
- 2Ask about an unseen age
Age 60 is not a key in the lookup, so the function falls back to its default answer, no.
- 3Ask why that answer was given
The answer came from a default, not from any pattern. Nothing learned from the training data was used.
A perfect training score coexists with an answer that reflects no learned pattern. The training score measured memory, not prediction.
The memorizer scored perfectly, yet it has learned nothing that would help with a customer it has not seen. This is the core of the correction. A training score measures how well a model reproduces answers it was shown. Generalization measures how well it predicts answers it was not shown. The two can differ enormously.
Generalization and Why Training Scores Mislead
Generalization is the ability of a model to make accurate predictions on new, unseen data that resembles the training set.
Generalization is a property the training score cannot report on its own. A model can be flawless on the examples it studied and still have no ability to predict new cases. For that reason, a model is judged on examples held back from training, not on the examples it already knows.
| Question | Training score | Generalization |
|---|---|---|
| What is measured? | How well the model reproduces answers it was shown | How well the model predicts answers it was not shown |
| Which data is used? | The training set | Unseen data, such as a held-back test set |
| Does 100 percent prove success? | No, it may reflect memorization | It is the real aim of building the model |
Two different questions that a training score can be mistaken for answering
A Rule That Fits the Table Perfectly
A novice data scientist wants to predict whether a customer will buy a boat, using records of past boat buyers and customers known not to be interested. The goal is to send promotional emails only to people who are likely to purchase. After studying the records, the scientist proposed this rule: if the customer is older than 45 and has fewer than 3 children or is not divorced, then they want to buy a boat. Asked how well it works, the scientist said it is 100 percent accurate.
There is also a way to fit the table perfectly without finding any real rule. Because no age appears twice in the data, one could list the ages of the boat buyers and declare that exactly those people want a boat. That rule is also perfectly accurate on the table, but it is memorization with a different label on it. Many rules can explain the training data perfectly, and perfect explanation of the training data is not the same as a rule that works on new customers.
Overfitting and Underfitting
Model complexity is the lever that connects these ideas. The source explains that if we allow ourselves to build very complex models, we can always be as accurate as we like on the training set. The complexity needed to chase every training answer is exactly what can break generalization. The two failures below sit at opposite ends of a complexity range, and a model that generalizes well lies somewhere between them.
Reading Complexity Against Two Scores
The comparison below lays the two failures side by side. Read each column from top to bottom: the model's complexity, how well it fits the training data, and how well it predicts new data. Judge the model by the new-data column, not the training column alone.
Mistakes Beginners Make With Training Scores
Common mistake Treating a perfect training score as proof that the model works
What it looks likeThe novice's rule is 100 percent accurate on the known table, and the scientist calls the job done.
Why it failsA training score measures how well the model reproduces answers it was shown. It does not measure generalization to new customers.
Do this insteadHold some data back as a test set and judge the model on that unseen data.
Common mistake Believing that any rule which fits the data perfectly is a real rule
What it looks likeListing the ages of the boat buyers fits the table perfectly, yet it is only a lookup.
Why it failsMany rules can explain the training data perfectly, and perfect explanation of the training data is not the same as a rule that works on new customers.
Do this insteadAsk whether the rule is simpler than the data would justify, and whether it depends on a handful of records.
Common mistake Assuming that more complexity always improves predictions
Why it failsA model that is too complex fits the training data too closely and may fail to generalize, which is overfitting.
Common mistake Assuming that a simple model is always safe
Why it failsA model that is too simple cannot capture the patterns in the training data, and it also fails to generalize, which is underfitting.
Diagnosing a Model From Its Scores
A model scores 100 percent on its training set and much lower on a held-back test set. Which failure is it most likely showing, overfitting or underfitting? Explain your reasoning using the model's complexity and its behavior on new data.
Hints
- Ask whether the model fits the training data very closely or fails to fit it at all.
- Compare the training score with the test score rather than looking at either one alone.
- Think about whether a model that memorizes details would be expected to fail on new examples.
A model scores poorly on both its training set and its test set. Which failure does this pattern suggest, and what kind of change to the model's complexity would you consider first?
Hints
- Underfitting means the model is too simple to capture the patterns in the training data.
- A poor training score is itself a warning sign, not only a poor test score.
Key Takeaways
- A model that is 100 percent accurate on the training set may still fail on new data, because a training score measures reproduction of known answers, not generalization.
- Generalization is the ability to make accurate predictions on unseen data that resembles the training set, and it is judged by holding some data back as a test set.
- Overfitting happens when a model is too complex and fits the training data too closely; underfitting happens when a model is too simple to capture the patterns in the data.
- Both failures produce poor predictions on new data, so check a model's behavior on new data and whether its rule is simpler than the data would justify.