Topic 5 of 5 · 4 min read
Data scale, variety and overfitting
Goal: Spot overfitting in a described training result and explain what more varied data or a held-out test would change.
A model is only useful if it works on cases it has never seen. With too little or too similar data, it memorises its examples instead, which is called overfitting, and a held-out test set is how you catch it.
Check yourself · 1 of 3
A model scores 98 percent on its training examples and 65 percent on a held-out test set. What does this suggest?
Why it matters
Imagine a student who memorises last year's exam answers. They score full marks on that exam and fail a new one with different questions. A model can do the same. Its score on its own training examples tells you little. What counts is how it does on new cases, such as the messages, photos and documents you give it.
Key ideas
- Generalising. The goal. The model learns a pattern that holds beyond its examples, such as "what makes a cat a cat", not "photo number 4,812 is a cat".
- Overfitting. The model fits the examples too closely, including their quirks and noise. It might learn that a stain on one scan means "ill", because that happened in a few training images.
- Why scale helps. With more examples, quirks average out and real patterns show up. A model with billions of settings can memorise easily, so it needs a very large amount of data to be pushed toward general patterns. This is why large language models train on huge collections of text.
- Why variety matters. Size alone is not enough. A million photos of cats on sofas teach little about cats outdoors. Examples should cover the range of real use: different lighting, accents, topics, languages and edge cases.
- The held-out test set. Before training, set aside some examples. The model never learns from them. After training, you score it on them. If it does well on training data and badly on the held-out data, it overfitted.
Before and after
Before: A team reports, "Our model gets 99 percent on its data, so it is ready." They tested only on examples it had trained on.
After: The team sets aside 20 percent of its data first. The model scores 99 percent on training data but 70 percent on the held-out set. The gap shows overfitting. The team adds more varied data and tests again.
What goes wrong
- Testing on training data. The score looks great and means nothing.
- A test set that leaks. If held-out examples are near copies of training ones, the test is too easy.
- Narrow data, wide claims. A model trained on one hospital's scans is sold as working everywhere, then struggles at another hospital with different machines.
When you hear a claim like "95 percent accurate", ask: on what data, and was it kept apart from training?
Examples
The memorising student
A model learns to detect fraud from 500 past cases and scores 100 percent on them. On new transactions it scores well below that. It memorised the 500 cases rather than learning the pattern of fraud. A held-out set of cases would have shown this before launch.
Narrow data
A voice model is trained on 10,000 hours of clean studio audio. In a noisy kitchen it fails often. The data was big but not varied. Adding recordings from cars, kitchens and streets would widen what it can handle.
Key points
- The goal of training is to generalise to new cases, not to memorise the examples.
- Overfitting means the model fits the quirks of its examples and does worse on new data.
- Large models with many settings can memorise easily, so they need very large and varied data.
- Variety matters as much as size: data should cover the range of real use.
- A held-out test set, kept out of training, shows whether a model really works on unseen cases.
Common mistakes
- Judging a model by its score on the data it trained on.
- Thinking more of the same kind of data fixes a narrow dataset.
- Letting near-duplicates of training examples into the test set.
- Reading a high accuracy number without asking what it was measured on.
Check yourself · 2 of 3
Why do we keep a test set out of training?
Check yourself · 3 of 3
A team has a million photos of dogs, all taken indoors in good light. How will its model most likely perform on a dog photographed outdoors at night?
Practice items, not counted towards your mastery.
Start here
- Machine Learning Crash Course (Google) (opens in a new tab)CourseFree
Free, hands-on lessons on how models learn from data, with exercises and clear figures.
- What is machine learning? (IBM Think) (opens in a new tab)ArticleFree
Plain overview of machine learning types and how training works.
- Neural networks series (3Blue1Brown) (opens in a new tab)VideoFree
Visual videos that show weights and training as nudging numbers to reduce error.
More for this topic
- Overfitting (Google Machine Learning Crash Course) (opens in a new tab)CourseFree
Short lesson on overfitting, with figures showing how training and test results diverge.
- What is overfitting? (IBM Think) (opens in a new tab)ArticleFree
Plain description of overfitting, its causes and common ways to reduce it.