Fourteen days
The ice cream seller now has fourteen days. If we use all of them for learning, no days are left to measure how wrong the model will be on new days.
Splitting the data
Eight days for training, in black. Three days for validation, in blue. Three days for testing, in yellow. The split is made before learning and is not changed later.
Learn from the training set only
The least squares line is computed from the eight training days only: sales = 1.59 · temperature + 4.43. The blue and yellow days do not enter the computation at all.
Training error
On the training days the loss is 4.31. The model has seen these days, so this number is optimistic: like taking an exam with the very questions you studied.
Validation error
On the validation days the loss is 0.87. The model has not seen these days. When comparing several models or settings, we look at this number and pick the best.
Test error
On the test days the loss is 1.86. This is the estimate of how the model does on new days. The test set is looked at once, after all choices are made.
Leakage
Changing the model after looking at the test error makes the test part of training, and the number becomes optimistic again. This is called leakage. Drag a test day: the line does not move, only the test error changes.
Why it matters
A model is worth what it does on data it has not seen. That is why competitions keep a hidden test set and companies hold back data before going live. With little data, cross-validation uses the same idea more efficiently.