Feature leakage in ML: Detect, Prevent, and Fix It
Blog post from Hex
Feature leakage in machine learning refers to the inadvertent inclusion of information during model training that would not be available during actual predictions, leading to models that perform well during validation but fail in production. This issue can arise from several sources, including target leakage, train-test contamination, and temporal leakage, where future data is incorrectly used to predict past events. Such leakage often remains undetected because it inflates both training and test metrics simultaneously, making models appear more reliable than they are. Effective prevention strategies include conducting exploratory data analysis (EDA) on properly split datasets to identify suspiciously high correlations and dominant features early on, and ensuring preprocessing steps are fit only on training data. Collaborative, reproducible workflows are emphasized as essential, allowing for thorough peer review and auditing of the data pipeline to catch leaks that automated checks might miss. AI-generated code, while speeding up development, can introduce new leakage risks, underscoring the importance of human oversight. By maintaining transparent and versioned analysis environments, teams can minimize the risk of feature leakage and build more trustworthy models.