When a model is accurate in the lab and drops in the field, the first place to look is not the algorithm. It is whether the training set contains information that was not available at the moment of the decision. Kaufman, Rosset, Perlich and Stitelman call this leakage: a variable tied to the target that cannot be known when the prediction has to be made, mixed into training.
Leakage arrives by two paths. The first is a column that comes into existence after the target. If the closing note of a fault record is fed to a model that is meant to predict the fault, the note carries the fault itself. The second is the same unit sitting in both the training set and the validation set. When rows are split at random, Monday's record of a device lands in training and Tuesday's in validation. The validation has not tested a new device.
Kaufman and colleagues separate the time of the target and the identity of the unit. The split is by unit, not by row. On a time series, validation uses records from after the training period ends. Scaling and filling of missing values are fit on the training set alone. The mean of the validation set does not enter that fit.
High accuracy is evidence for leakage, not against it. A column that tracks the target almost one for one shows that the model read the column, not that it learned the job. Accuracy falling after that column is removed is the expected result.
On a FenergyTech model job the unit and the time are named before the split is written. If the unit is not named, shuffling rows is not a validation.
The leakage Kaufman and colleagues describe does not show in a column's name. The "closing note" of a fault record is written after the fault is over. If the note feeds the model, the model reads the sentence "bearing was changed" and acts as if it knew the fault. The note is not there at the moment of the prediction. A column that comes into existence after the time of the target leaves the training set.
Two days of the same device are leakage as well. If the rows are shuffled and 80 percent go to training, Monday of a machine stays in training and Tuesday in validation. The validation has already seen that machine's vibration signature. The split is by machine identity. On a time series, validation uses records from after the day training ended. Scaling is fit on the mean of the training set alone. If the mean of the validation set enters the scale, the test has seen its own distribution.
High accuracy is evidence for leakage in this case. If accuracy falls when the note is removed, the fall is the expected result. Accuracy that does not fall means another leaking column still has to be looked for.
Sources: S. Kaufman, S. Rosset, C. Perlich, O. Stitelman, "Leakage in Data Mining: Formulation, Detection, and Avoidance", ACM Transactions on Knowledge Discovery from Data, vol. 6, no. 4, article 15, 2012.
Planning a similar project?
We can talk through how the topic in this article applies to your product.