Level 2 · Module 6 · 10 minutes
Training, testing and leakage
- Explain why data is split into training, validation and test parts.
- Describe data leakage and give an example.
- Explain why time can matter when splitting data.
A model can appear excellent if you test it on the same examples it learned from. It has seen the answers. A student who has memorised last year's exam paper may score well on that paper and badly on a new one. Models have the same weakness, so data is divided.
Three piles
- Training data: used to adjust the model's internal numbers.
- Validation data: used to compare settings and choices while building.
- Test data: locked away until the end, used once to estimate how the model will behave on new cases.
The test set works because it is unseen. If it is used again and again to tweak the model, it stops being a test and becomes part of training by another name.
Data leakage
Leakage is when information the model would not have at decision time sneaks into the training features. The model then looks brilliant in testing and fails in use, because the helpful clue is missing.
An example: predicting whether a delivery will be late, and including the time the delivery was completed. The model is using the future to predict the future. Another example: a field filled in by staff only after they have investigated a case. A third: duplicate records spread across training and test, so near-identical rows appear in both piles.
Leakage is usually a data design error, not a bug the software reports. The defence is to check each feature with one question: at the moment of the decision, would this value really be known?
Time matters
When behaviour changes over months, splitting at random mixes the future into training. A safer approach is to train on older data and test on the most recent data, which mirrors how the model will be used.
Groups also matter. If records from the same customer appear in both training and test, results are flattering. Split by customer, by machine or by site, depending on what a genuinely new case means.
Being careful, not paranoid
A class exercise that divides printed records into three piles demonstrates the procedure. It is a simulation, because no model learns from the piles. The reasoning transfers directly. Ask often what is in the training data that will not be there later, and why the test pile was chosen as it was.
Common misconception
Testing a model on the same examples used for training is acceptable because that is what the model was built for. Training data cannot show how the model will behave on new cases. Performance must be measured on data held back from training, ideally including the most recent period, and the test part must not be used for tuning.
Guided practice
Imagine predicting which repair jobs will take longer than a day. List the features, then mark any that would only be known after the job is finished. Describe how you would split older and newer jobs between training and testing, and explain in two sentences why a random split could be misleading. This is a paper design exercise; no model is trained.
Knowledge check
Independent practice
Write a short example from your own work or daily life and decide whether it is AI, ordinary software or a mixture. Then explain why. Save it in your notes; no account is required.
Last reviewed: · Report a problem