EasyDeepLearn

How does imputation cause data leakage?

medium

Answer

  • Fitting imputer (mean / KNN) on train + test together sees test values → optimistic evaluation.
  • Same for standardization / target encoding.
  • Fix: fit imputer ONLY on training fold inside cross-validation; apply to test/validation via .transform().
  • Use sklearn.pipeline.Pipeline or ColumnTransformer to enforce.
  • For time series: use train-window statistics only.
  • Never use future observations to fill past.
Check yourself — multiple choice
  • Not real
  • Fitting imputer on train+test sees test values → optimistic eval; fit only on train inside CV + Pipeline / ColumnTransformer + time-window aware
  • Random
  • Always fine

Imputation leakage: fit on train only inside CV; use Pipeline.

#data-quality#pipeline

Practise MLOps & Data Quality

215 interview questions in this topic.

Related questions