Keep a feature unavailable at prediction time out of training

Return to the home row after each number or separator. · 178 words

Prediction-time availability means that a feature must already be known at the exact moment the prediction is made. A bookstore predicts whether a popular title will sell out before the evening sale. Orders placed so far are available, but the number of signed deliveries that day is not known yet. If that delivery count appears in the historical table and is used for training, the model may learn from information from the future. This is data leakage, and it makes test results too optimistic.

Consider a weather app that predicts rain at 6:00 a.m. A column named rain_fall_measured_at_noon cannot be used, because noon is later than the prediction time. The safe training table should contain only values recorded by 6:00 a.m., or a forecast that existed then. Missing values should not be filled with the future measurement. When evaluating, rebuild each row as it would have looked at its own prediction cutoff, including on the newest data. A feature can be useful in general yet invalid for this task because it is unavailable when the decision is needed.

Check your recall

A historical table contains a feature recorded after the prediction timestamp. Should it be used for training?

Check your answer

No, not for that prediction task, because it creates future information leakage. Remove it or create a past-only version of the table, and evaluate using only the features that were available at each prediction cutoff.

Sources and credits

Original KeyTouch lesson. Background reading · Google · Machine Learning Crash Course.