Introduction to AI Lesson 20 of 25

Part 2 · Lesson 10 · 5 min

Testing honestly: training data vs test data

Would you trust a student's exam score if they had seen the exact questions the night before?

Of course not. Machines deserve the same suspicion.

A model can get very good at the examples it trained on. That tells you surprisingly little. The question that matters is how it does on examples it has never seen.

The leaked exam

The student did not learn the subject. They learned the answers to one paper. Models can do exactly the same thing.

Seal some cards away

The fix is simple and strict. Before training starts, you put a slice of your examples in a sealed envelope. That slice is the test set. The rest is the training set.

Keep some cards sealed

The score on the sealed cards is the honest one. It is often lower than the training score, and that gap is useful information, not bad news.

Two more rules. The test cards should look like the real world the model will face. And the world keeps changing, so a model that tested well last year needs checking again.

Go deeper optional

In practice there are often three piles. The training set is for learning. A validation set is for trying out different versions and picking the best one. The test set stays sealed until the very end, for one final honest score.

Data leakage is when information from the test pile sneaks into training, for example the same patient appearing in both piles. The score then looks great and means little. It is one of the most common ways impressive AI results turn out to be wrong.

Check yourself

1. Why keep a test set separate?

2. A vendor reports 99% accuracy on the data used to train the model. What should you ask?

3. A model tested well two years ago. Is it still fine?