Machine Learning Fundamentals interview question · Most asked
What is overfitting, and how do you prevent it?
Definition Asked in Machine Learning Engineer interviews
Summary
Overfitting is when a model learns the noise and quirks of its training data instead of the general pattern, so it scores well in training but poorly on new data. Prevent it with more or better data, simpler models, regularisation, early stopping, cross-validation and honest evaluation on held-out data.
Longer Answer
Techniques:
- Regularisation: L1/L2 penalties, dropout, weight decay; limits on tree depth or leaf size.
- Early stopping on a validation set for iterative learners (gradient boosting, neural networks).
- Data: more examples, augmentation, removing leaky or ID-like features.
- Model choice: fewer parameters, ensembles (random forests average away variance).
- Evaluation: cross-validation for model selection and a final untouched test set; tuning hyperparameters on the test set overfits to it too.
Key Points
- Great training score, poor generalisation.
- Regularise, stop early, simplify.
- More data and fewer leaky features.
- Never tune on the test set.
Explanation
What interviewers look for
Several concrete techniques and awareness that hyperparameter tuning can overfit the validation data.
More Machine Learning Fundamentals questions
- Explain the bias-variance trade-off.
- Your model scored well offline but performs badly in production. What do you check?
- What is data leakage, and how do you detect it?
- Which metrics would you use for a classification model, and when is accuracy misleading?
- How do you split data for training, validation and testing, and what is cross-validation?
- What is the difference between supervised, unsupervised and reinforcement learning?
- Compare decision trees, random forests and gradient boosting.
- Design a system that serves predictions from a trained model to a web application.