32. Features and Labels in Machine Learning
32.3 Label Leakage (Do Not Cheat the Model)
Why. Label leakage means your features secretly include the answer (or something only known after the answer). The model “cheats” in the notebook and fails in real life.
What. Example: predicting was_late while including actual_delivery_minutes as a feature. In production, when the rider leaves, you do not yet know actual minutes. The feature is illegal for that prediction moment.
How.
Leakage hunt
- Write the prediction moment: “When the order is packed, before dispatch.”
- For each feature ask: “Do I know this value at that moment?”
- If no → drop it from X.
- Also drop columns that are just another spelling of y.
# Bad feature list (leakage) vs safer list
y = "was_late"
leaky_X = ["items", "distance_km", "actual_delivery_minutes"] # minutes leak the answer
safer_X = ["items", "distance_km", "rain_mm", "hour_ist"]
print("Use:", safer_X)
print("Avoid for this problem:", leaky_X)
Ravindra Bagale's Tip
99% accuracy + leakage = sweet poison. Nehmi vichara: “He column prediction chya aadhi mahiti aahe ka?” Dhyan rakho!