How do you handle missing values in a dataset before training a model?
What the interviewer wants to hear
- First understand why values are missing (random or meaningful)
- Simple imputation with median, mean or most frequent value
- Add a missing-indicator feature when missingness carries signal
- Fit imputers on training data only to avoid leakage
- Some models such as gradient boosting handle missing values natively
Model answer
I start by asking why the values are missing. If a field is missing because a user skipped an optional step, the fact that it is missing may itself predict the target. If it is a logging bug, I fix the pipeline instead of patching the model. For numeric features I often impute the median, which is robust to outliers, and for categories I use the most frequent value or a separate "unknown" category. I usually add a binary indicator column so the model can learn from the missingness. All imputers are fitted only on the training split inside a pipeline, so validation and serving use the same learned values without leakage. Gradient boosting libraries can handle missing values natively, which is often the simplest option. If a column is mostly empty and adds little, I drop it.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Machine Learning Engineer questions
- What is overfitting, how do you detect it, and how do you reduce it?
- Explain precision and recall with a real example. When would you favour one over the other?
- How does gradient descent work, and what is the role of the learning rate?
- What are the training, validation and test sets used for, and how do you split them?
- Why should you build a simple baseline before a complex model? Give examples of good baselines.
- Explain the bias-variance trade-off and how it guides your choice of model.
- What is an embedding, and how would you use embeddings in a product feature?
- When would you choose a tree-based model like gradient boosting over a linear model, and when not?
- Explain in simple terms how self-attention works in a transformer.