How do you handle missing data?
Short answer
Find out why it is missing first. The mechanism determines the treatment, and imputation before understanding is how bias gets baked in.
Full answer
Start with why. The three mechanisms lead to different treatments:
- Missing completely at random — missingness is unrelated to anything. Dropping rows is unbiased, just wasteful.
- Missing at random — missingness depends on other observed variables. Imputation conditioned on those variables works.
- Missing not at random — missingness depends on the missing value itself. Income missing because it is high, for example. No imputation fixes this; the missingness is itself information.
Then choose:
- Add a missingness indicator column. Cheap, and often one of the most predictive features you have.
- Impute inside the cross-validation fold, never before it.
- For tree models, consider leaving NaN in place — several implementations handle it natively and learn a split direction.
- Drop the column if it is mostly missing and the missingness carries no signal.
What the interviewer is assessing
The differentiator is whether the candidate investigates before treating. A recital of imputation techniques with no mention of mechanism suggests a course rather than practice.
The strongest concrete detail is the missingness indicator. In a great many real datasets, "this field was blank" predicts the target better than any imputed value, because it encodes something about how the record was created.
The second strongest is fitting the imputer inside the CV fold — leakage through a globally-fitted imputer is extremely common.
If you get stuck
- Hint 1. Does the reason it is missing matter?
- Hint 2. Is the fact that a value is absent ever informative by itself?