Your model appears to work with 99% accuracy, but in reality it is simply peeking at the future. The most subtle and dangerous mistake in machine learning: Data Leakage.
It happens when information that would not be available at prediction time leaks into the model during training. The model ends up predicting the future by already knowing it — like a student who peeked at the exam questions beforehand.
One of the features is directly tied to the target variable and is only measured after the outcome occurs. The model already knows the answer.
Test data bleeds into the training process. Normalization, feature selection, or cleaning is performed on the entire dataset before splitting.
In time-series problems, data from the future is fed into the model at training time. Train/test split must follow chronological order, not random shuffling.
Imagine a teacher who hands out the exam questions in advance and then administers the very same exam. Students score 100%. But in the real world, they fail miserably. That is exactly what Data Leakage is — the model is trained on information it will never have access to in production.
You are building a bank loan default prediction model. Select any of the 8 features below. Accuracy metrics and real-world performance will update in real time. Which features cause leakage?
The 6 cases below are inspired by real industry mistakes. Read each scenario, form your own answer, then flip the card to reveal the truth.
Wrap every preprocessing step inside a Pipeline. fit() only sees train data, transform() applies to both train and test.
Split the data, then explore. Perform EDA only on the train set. Don't even look at the test set.
Never randomly split time-series data. Train on the past, test on the future. Use TimeSeriesSplit.
For every feature, ask: "Will I have this information at prediction time?" If the answer is "no", that feature leaks. Drop it.
Chances are you have data leakage.
Always ask yourself: "Will this feature actually be available at the moment of prediction?"
If the answer is "no", that feature is fooling your model.