How do you deal with missing values in a dataset?
Machine learning basics · Beginner 3
Short answer
First find out why values are missing, because that decides the fix. Then drop rows or columns only if little is lost, impute with the median, most frequent value or a model, and often add a flag saying the value was missing. Fit any imputation on training data only.
Deeper answer
Missing can carry meaning: a blank income field on a loan application may itself predict risk, so a missing-value indicator often helps. Values missing completely at random are the easy case; values missing for a reason need care.
In pandas, start with isna().sum() to see how much is missing per column. Use a scikit-learn pipeline with SimpleImputer so cross-validation refits it per fold. Gradient boosting libraries can handle missing values natively, which is worth mentioning.
What a strong answer covers
- Asks why values are missing
- Drop only when little is lost
- Impute with median, mode or a model
- Adds a missing-value flag
- Fits imputation on training data only
Answer it out loud in the mock interview about 1 min
Follow-ups to expect
- Why fit the imputer on training data only?
- When would you drop a column instead?
Common mistakes
- Filling with the mean computed on all data
- Dropping rows without checking how many are lost
Learn it
- How would you tell whether a new model really performs better in an A/B test?
- Explain the bias-variance trade-off.
- What is the difference between a random forest and gradient boosting?
- How does k-means work, and how do you choose k?
- What is data leakage, and how do you prevent it?
- Give an example of feature engineering that made a model better.
- How do you know whether you have enough training data?
- How do you handle a heavily imbalanced classification problem, such as fraud detection?
- What is the difference between linear and logistic regression?
- Walk me through an ML project you did, end to end.
- What is overfitting, and how do you spot it?
- Explain precision and recall with an example.
- What do L1 and L2 regularisation do?
- What is the difference between supervised and unsupervised learning?
- Why do we split data into training, validation and test sets?
- What is the difference between training and inference?