What leakage is
Kaufman and colleagues defined leakage as information in the training data that would not be available when the model is used.1 The model learns from it, scores well in testing, and then loses that information in real use.
In business data, most leakage is about time. A value that was only known after the date of the prediction finds its way into the inputs, or into the examples the model learns from.
How common it is
Kapoor and Narayanan surveyed the use of machine learning in science. They found leakage in 17 research fields, affecting hundreds of published papers, and grouped it into eight types. Several of them are about time, such as using data from after the period being predicted.2
In a business, the same mistake shows up as a back-test that the live model never matches.
Random splits flatter models on dated data
The usual way to test a model is to hold out a random share of the rows. When rows have dates, this puts later rows in the training set and earlier rows in the test set. The model is tested on a past it has already seen the future of.
Rubachev and colleagues built TabReD from industry datasets with real time order. They found that random splits can give overly optimistic estimates, and that the choice of split changes the scores, their spread, and even which method comes out on top.3
Forecasting settled this question long ago. Tashman reviewed out-of-sample testing and set out the case for rolling forecast origins.4 Hyndman and Athanasopoulos describe the same method as time series cross-validation.5 Bergmeir and Benítez studied when cross-validation is safe for time series and when it is not.6
Five leaks common in business data
- Answers that are known only later. A 12-month default flag on a loan made last month says “not bad yet”, not “good”. Using it as an answer teaches the model that recent loans are safe.
- Inputs computed after the prediction date. A month-end balance used for a score made on the 15th of the month.
- Fields overwritten after the event. A status code that changes to “written off” once an account defaults, read back as if it had always been there.
- Plans entered after the fact. A promotion added to the calendar after the forecast was made, used in testing as if it had been known.
- The same customer on both sides. Rows of one customer in both the training and the test data, so that the model recognises the customer instead of the pattern.
Back-testing the right way
A fair back-test stands at a date in the past and uses only what was known on that date.
- Pick a past date to stand at.
- Take only the rows, values and answers that were known by that date.
- Predict what happens after it.
- Compare the predictions with what actually happened.
- Repeat for several dates, and compare with the current method on the same dates.
How tabSutra keeps time
- Every row carries the time its values became known and the time its answer became known.
- A row to predict reads only answers that were known strictly before its own values were known.
- A row reads the earlier rows of its own customer, account or machine, and nothing dated after it.
- In a database, every table is read as it stood on the date of the prediction.
- Built-in evaluations hold out the latest period, as it would be in real use.
These rules are applied by the model itself, not by a pipeline that someone has to get right for every question.
What it does not fix
A model can only respect the dates it is given. A field that is itself filled in after the outcome, such as a collections status, has to be marked so that it is not read. Dates have to be correct. And the question has to be defined honestly: an outcome window that is too short for the business will be predicted accurately and still be of little use.