Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Evaluating Models  ›  Lesson

Train, Validation and Test Sets

Machine Learning 13 minA model must be judged on data it never learned from, so data is split into training, validation and test sets in the same way the model will be used, and the test set is touched only once.

Train, Validation and Test Sets

Pantry wants a model that predicts which Pantry Plus members will cancel next month, so the voucher from the expected value lesson goes to the right people. A teammate's first model is thrilling: on the data it learned from, it spotted 97 of every 100 members who cancelled. Run on the following month, it spotted 52. The model had not learned who cancels. It had memorised who had cancelled.

The rule

Judge a model only on data it never learned from.

A flexible model can fit the rows it is shown almost perfectly, noise included. That is overfitting, and a score on seen data measures memory, not skill. So the data is divided three ways:

  • Training set: the model learns its patterns here.
  • Validation set: you compare models, tune their settings and choose the decision threshold here. Each choice you make by looking at it leaks a little of it into the model, so its score slowly becomes optimistic.
  • Test set: locked away until the end and used once, to estimate how the finished model will do in the real world.

How you split matters as much as whether you split. The rule is to split the data the way the model will be used:

  • If rows are independent and the future looks like the past, a random split is fine.
  • If the model predicts the future, train on the past and test on later periods, or the model learns from information it will never have.
  • If one person or store has many rows, keep all of their rows on the same side of the split.

The shortcut

Ask "when will this model run, and on whom?" Then build the split to recreate that moment.

Splitting the churn dataStep 1 of 4
  1. How the model is used

    On the 1st of each month, Pantry scores every current member for the chance they cancel during that month.

If you check the test score after every tweak, it quietly becomes a second validation set, and you lose your only honest estimate.

Drills

Answer fast — trust the rule.

quick drill

The churn model spots 97% of cancellers in its own training data. Why is that not evidence it works?

quick drill

What is the validation set for?

quick drill

The model will predict next month's cancellations. Which split fits?

A dataset of 10,000 rows is split 70/15/15 into training, validation and test. How many rows are in the test set?
10000×15100= ?10000 \times \tfrac{15}{100} = \,?
quick drill

You checked the test score after each of 12 tweaks and kept the best version. What is true now?

Remember

  • Judge a model only on data it never learned from.
  • Split the way the model will be used: by time for forecasts, by person when people repeat.
  • Trap: peeking at the test set until it becomes a second validation set.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy 97% became 52%

Explain to your teammate why their churn model spotted 97% of cancellers in training but only 52% the next month, and describe how you would split Pantry's member-month data so the next evaluation is honest.