Machine Learning Fundamentals interview question · Most asked
How do you split data for training, validation and testing, and what is cross-validation?
How you'd do it Asked in Machine Learning Engineer interviews
Summary
Train on one part, tune choices on a validation part, and report final performance once on a held-out test part. k-fold cross-validation rotates the validation fold through the training data so every row is used for both training and validation, giving a more stable estimate on small datasets.
Longer Answer
- Typical splits: 70/15/15 or 80/10/10; with lots of data, the validation and test sets can be smaller in percentage.
- Stratify classification splits so class proportions match.
- Time series: split by time (train on the past, validate on the future), never randomly;
TimeSeriesSplitor walk-forward validation. - Groups: keep all rows from one user, patient or session in the same split (
GroupKFold) to avoid leakage. - Fit preprocessing (scalers, encoders, imputers) on the training fold only, ideally inside a pipeline.
Key Points
- Train, tune on validation, report once on test.
- k-fold for stable estimates on small data.
- Stratify classes; split time series by time; group related rows.
- Fit preprocessing only on training data.
Explanation
What interviewers look for
Knowing when random splits are wrong (time, groups) and how preprocessing leaks.
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?
- What is overfitting, and how do you prevent it?
- 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.