How does imputation cause data leakage?
mediumAnswer
- 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.PipelineorColumnTransformerto 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
- What are common sources of data leakage in an ML pipeline?
- How does time-based leakage happen and how do you prevent it?
- What is a data contract?
- How do you prove there is no training-serving skew?
- What is point-in-time correctness, and how does violating it look in practice?
- What is data drift and how do you detect it?