Machine Learning Interview Questions for 5 Years Experience
40 questions with answers for candidates with 5 years of experience — 23 medium, 17 hard.
What interviewers expect: 5 years experience
At five years, interviews include ML system design: feature stores, batch versus real-time architecture, model registries, CI/CD and scaling. You are expected to mentor juniors, review model designs and choose which problems are worth solving. Expect questions on fairness, governance and how you measured the business value of your models.
This set is weighted towards Model Evaluation and Tuning (8), Decision Trees and Ensembles (7), MLOps and Deployment (6), Data Preprocessing and Feature Engineering (5).
ML system design MLOps architecture Mentoring and reviews Business value measurement
Solved at this levelStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
✓ 3 questions free • Unlock the rest in seconds
01
A new model has slightly better AUC but worse precision in the top 1,000 cases the team acts on. Which do you pick?
I would pick the model that does better where decisions are actually made. If the team only reviews the top 1,000 cases, precision at 1,000 or recall at that cut-off matters more than global AUC. I would make that the primary metric in future comparisons, and confirm the result holds across several time periods before switching.
02
What is the difference between label encoding and ordinal encoding?
Both map categories to integers. In scikit-learn, LabelEncoder is meant for the target variable, while OrdinalEncoder is for input features. Integer encoding implies an order, so it is fine for truly ordered values like low, medium, high, or for tree models, but it can mislead linear models on nominal data like colours. For nominal features with linear models, prefer one-hot encoding.
Gradient boosting starts with a simple prediction, like the mean, then repeatedly fits a small tree to the negative gradient of the loss, which for MSE is just the residuals. Each tree's output is scaled by a learning rate and added to the ensemble. A lower learning rate with more trees usually generalises better. Any differentiable loss can be used, which makes it flexible.
04
Describe a time you found a serious data quality issue late in a project.
Situation: two days before a demo, I noticed sales for one region were doubled. Task: fix it without missing the deadline. Action: I traced it to a join that duplicated rows on a non-unique key, fixed the join, added row-count assertions to the pipeline and retrained. I informed my lead immediately with the impact. Result: the demo went ahead with correct numbers, and the assertions caught a similar issue later.
05
The fraud team can only review 500 alerts a day. How do you set the threshold?
Instead of 0.5, rank transactions by predicted probability and pick the threshold that yields about 500 alerts per day on recent data. Then report precision and recall at that cut-off, or precision at k. I would monitor daily alert volume because drift can change it, and recompute the threshold periodically. If cost data exists, I would choose the threshold that maximises expected savings.
06
Marketing wants customer segments for campaigns. How do you approach it?
I would agree on the purpose first, such as retention or upsell. Then build RFM features (recency, frequency, monetary) plus category preferences, log-transform skewed values and scale them. I would try k-means for k between 3 and 8, use silhouette and business review to pick k, profile each segment and give them clear names. Finally, test segment-based campaigns against a control group.
07
How do you build a scikit-learn pipeline for mixed numeric and categorical data?
Use ColumnTransformer inside a Pipeline so preprocessing is fit only on training folds.
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
num = Pipeline([('imp', SimpleImputer(strategy='median')), ('sc', StandardScaler())])
pre = ColumnTransformer([
('num', num, num_cols),
('cat', OneHotEncoder(handle_unknown='ignore'), cat_cols)
])
model = Pipeline([('pre', pre), ('clf', LogisticRegression(max_iter=1000))])
08
A demand forecast is consistently under-predicting during festivals. How would you fix it?
The model lacks festival information. I would add features for festival dates such as Diwali or regional holidays, days-to-festival, and past festival uplift for the same item. If the business cost of stock-outs is higher than over-stock, I would use a quantile loss for a higher percentile. Then validate specifically on past festival periods, not just the average error.
09
Your cross-validation score is 0.85 but the test score is 0.70. What could explain it?
Possible causes: leakage inside CV, such as preprocessing or feature selection fit outside folds; repeated tuning that overfit the CV folds; a test set from a different time period or population; or duplicate entities across folds but not test. I would check pipeline structure, switch to time-based or group splits that match how test data differs, and compare feature distributions between the two sets.
10
Your team retrains models manually in notebooks every month. How would you improve it?
I would convert the notebook into a versioned training pipeline with separate steps for data extraction, validation, feature building, training and evaluation, scheduled with Airflow or a cloud pipeline. Each run would log to MLflow, compare against the production model on a fixed holdout, and register the new model only if it passes thresholds. Promotion would stay a reviewed step, at least initially.
11
What should you monitor for a model in production?
Monitor service health such as latency, error rate and throughput; input data quality such as missing values, schema changes and out-of-range values; feature and prediction distribution drift; and real performance once labels arrive. Also track business KPIs the model influences. Set alerts with thresholds and owners, and keep a dashboard so issues are found before users report them.
12
Your classifier works well overall but poorly for one customer segment. What do you do?
I would measure metrics per segment to confirm, then check if that segment is under-represented or has different feature distributions. Fixes include collecting more data, sample weighting, segment-specific features, or a separate model if the behaviour is truly different. If the segment relates to a protected attribute, I would also review fairness metrics and involve the compliance team.
13
Check calibration with a reliability curve and Brier score.
from sklearn.calibration import CalibrationDisplay
from sklearn.metrics import brier_score_loss
proba = clf.predict_proba(X_test)[:, 1]
print('Brier', brier_score_loss(y_test, proba))
CalibrationDisplay.from_predictions(y_test, proba, n_bins=10)
plt.show()
Points on the diagonal mean predicted probabilities match observed frequencies.
14
Why can impurity-based feature importance be misleading?
Impurity-based importance is computed on training data and favours high-cardinality or continuous features, which offer more split points, even if they are noise. It also splits credit between correlated features. Permutation importance on validation data, which measures the score drop when a feature is shuffled, is more reliable, and SHAP values give consistent per-prediction attributions.
15
Your tree model predicts higher risk for customers with higher income, which is illogical. What do you do?
First check whether data supports it, perhaps due to confounding or a small segment. If the relationship should be one-directional for business or regulatory reasons, I would apply monotonic constraints, available in XGBoost, LightGBM and HistGradientBoosting, so risk can only decrease with income. Then compare validation metrics; usually the loss is small and the model becomes more trustworthy.
Stacking trains several diverse base models and then a meta-model on their out-of-fold predictions to combine them. It often gives a small accuracy gain, common in competitions. In production it adds complexity, latency and maintenance, so it is worth it only when the gain has clear business value. scikit-learn provides StackingClassifier and StackingRegressor.
17
How does ordinary least squares find the regression coefficients?
OLS chooses coefficients that minimise the sum of squared residuals between actual and predicted values. It has a closed-form solution, beta = (X^T X)^-1 X^T y, when X^T X is invertible. For very large or ill-conditioned data, gradient descent or a pseudo-inverse is used instead. Squaring errors penalises large mistakes heavily, which makes OLS sensitive to outliers.
18
What is the difference between offline evaluation and online A/B testing of a model?
Offline evaluation measures metrics like AUC on historical holdout data; it is fast and cheap but cannot capture user behaviour changes or feedback loops. Online A/B testing exposes a share of real traffic to the new model and measures business outcomes like conversion or loss rate. Offline gains do not always translate online, so important models are validated with A/B tests or shadow deployments.
19
40 percent of values in an important income column are missing. What do you do?
I would study the missingness pattern first, for example whether self-employed applicants skip it. I would add a binary was_missing feature, impute with the median within relevant groups or use IterativeImputer, and compare against models that handle missing values natively, like HistGradientBoosting or XGBoost. I would also raise the issue with the data owner so collection can improve.
20
Which hyperparameters matter most when tuning a gradient boosting model?
The key ones are learning_rate and number of trees, tuned together with early stopping; tree complexity through max_depth or num_leaves and min_child_samples; and randomness through subsample and colsample_bytree. Regularisation terms like lambda and alpha help on noisy data. A common approach is to fix a small learning rate such as 0.05, use early stopping for trees, then tune complexity.
21
When should you use TimeSeriesSplit or GroupKFold instead of normal k-fold?
Use TimeSeriesSplit when data is ordered in time, so each validation fold comes after its training data and no future information leaks back. Use GroupKFold when multiple rows belong to the same entity, such as several visits per patient, so the same entity never appears in both train and validation. Normal k-fold in these cases gives over-optimistic scores.
22
What is the difference between a generative and a discriminative model?
A discriminative model learns the decision boundary or P(y|x) directly, such as logistic regression or SVM. A generative model learns how data is produced, P(x|y) and P(y), and can generate new samples, such as Naive Bayes or Gaussian mixture models. Discriminative models usually give better accuracy with enough data, while generative models handle missing data and small samples better.
23
You need prediction intervals, not just point estimates, for delivery time. How?
Options are quantile regression, training separate models for the 10th and 90th percentiles with GradientBoostingRegressor(loss='quantile') or LightGBM; conformal prediction, which wraps any model and gives intervals with guaranteed coverage; or bootstrapping. I would check calibration: about 80 percent of actual values should fall within an 80 percent interval on a holdout set.
24
Your training loss is not decreasing at all. What could be wrong?
Common causes are a learning rate that is too high or too low, unscaled features, a bug in labels or feature alignment, wrong loss for the task, or data that has been shuffled away from its labels. I would try overfitting a tiny subset first; if the model cannot even fit 50 rows, there is a bug. Then check scaling, learning rate and gradient values.
The ROC curve plots true positive rate against false positive rate at every threshold, and AUC is the probability that a random positive is ranked above a random negative. It is threshold-independent. On heavily imbalanced data, like 0.5 percent fraud, ROC-AUC can look high even when precision is poor, so the precision-recall curve and PR-AUC give a more honest picture.
27
Explain a single prediction with SHAP for a tree model.
import shap
explainer = shap.TreeExplainer(model)
sv = explainer(X_val)
shap.plots.waterfall(sv[0])
shap.plots.beeswarm(sv)
The waterfall shows how each feature pushes one prediction up or down from the base value; the beeswarm shows global importance and direction. TreeExplainer is fast and exact for tree ensembles.
28
Lasso dropped a feature the business considers very important. How do you handle it?
Lasso often keeps only one of a group of correlated features, so the dropped feature may be redundant rather than useless. I would check correlations, try Elastic Net which keeps correlated groups, and compare cross-validated performance with the feature forced in. I would explain the trade-off clearly; if the accuracy difference is small, keeping the feature for trust and interpretability is reasonable.
Isolation Forest builds random trees that split on random features and random thresholds. Anomalies are few and different, so they get isolated in fewer splits, giving shorter average path lengths. The anomaly score comes from that path length. It is fast, works without labels and scales well. The contamination parameter sets the expected share of anomalies and determines the threshold.
30
Tell me about a time you had to explain a model's error to a business team.
Situation: a sales forecast missed by 18 percent in one month. Task: explain why to the category team. Action: I broke the error down by region and found most came from a sudden promotion not in our data. I showed a simple chart and proposed adding a promotion calendar feed. Result: the team shared promotion plans in advance, and the next quarter's error fell below 8 percent.
31
New categories appear in production that were not in training data. How do you handle it?
Make the encoder tolerant: OneHotEncoder with handle_unknown='ignore' or infrequent_if_exist, or map unseen values to an 'Other' bucket. Monitor the share of unseen categories as a drift signal. If new categories become common, such as a new city launch, retrain with fresh data. Tests in the inference pipeline should include unseen values so the service never crashes.
32
Random forest and LightGBM give the same AUC. Which would you deploy?
I would compare beyond AUC: model size, inference latency, training time, calibration and stability across time periods. LightGBM is usually smaller and faster to score, while random forest needs less tuning and is less prone to overfitting. If both are equal, I would choose the one that is cheaper to run and easier for the team to maintain and retrain.
Log loss, or cross-entropy, is the negative average log of the probability assigned to the true class. It heavily penalises confident wrong predictions, such as predicting 0.99 for an event that does not happen. It evaluates probability quality, not just ranking, so it suits problems where probabilities drive decisions. Lower is better, and a constant base-rate prediction is the baseline to beat.
34
Your real-time model API takes 400 ms but the requirement is under 50 ms. What do you do?
Profile first to see whether time goes to feature lookup, preprocessing or the model. Then cache or precompute features, load the model once at startup, reduce trees or features, use a faster library like LightGBM or ONNX Runtime, and batch requests if possible. Run several workers and keep the service close to its data store. Re-measure p95 and p99 latency, not just the average.
The kernel trick computes dot products of data in a high-dimensional feature space without explicitly transforming the data, using a kernel function such as RBF, exp(-gamma times squared distance). This lets linear algorithms like SVM learn non-linear boundaries efficiently. In RBF SVMs, larger gamma makes each point's influence more local, which can lead to overfitting.
36
Get a bootstrap confidence interval for a test metric.
I would check the test first: enough sample size and duration, correct randomisation, and no bugs in serving such as stale features. Then investigate whether offline metrics really reflect user value, for example optimising clicks rather than purchases, or popularity bias. Segment-level analysis may show gains in some groups. I would revise the offline metric to better match the online goal.
38
What are shadow deployment and canary release for models?
In shadow deployment the new model receives a copy of live traffic and its predictions are logged but not used, so you can compare it with the current model safely. In a canary release a small share of real traffic, such as 5 percent, is served by the new model, and the share grows if metrics stay healthy. Both reduce the risk of a bad model affecting all users.
39
Tell me about a time a production model failed and how you communicated it.
Situation: our daily scoring job silently produced all-zero scores for two days after an upstream column was renamed. Task: fix it and inform affected teams. Action: I rolled back to cached scores, patched the feature mapping, and sent a short note explaining impact, cause and fix. I then added schema validation and a check on score distribution. Result: the issue never repeated, and teams trusted our alerts more.
40
What is a Gaussian Mixture Model and how is it different from k-means?
A GMM assumes data comes from a mix of Gaussian distributions and fits their means, covariances and weights with the Expectation-Maximisation algorithm. Unlike k-means' hard assignments, GMM gives soft probabilities of belonging to each cluster and can model elliptical clusters of different sizes. You can choose the number of components using BIC or AIC.
Frequently asked questions
What is asked in Machine Learning interviews for 5 years of experience?
At five years, interviews include ML system design: feature stores, batch versus real-time architecture, model registries, CI/CD and scaling. You are expected to mentor juniors, review model designs and choose which problems are worth solving. Expect questions on fairness, governance and how you measured the business value of your models.
How many questions should I practise before a Machine Learning interview?
Work through all 40 questions here, then the company-wise sets for the employers you are targeting. Quality matters more than count: be able to explain why each answer is right.
Which topics matter most for 5 years of experience?
Focus first on ML system design, MLOps architecture, Mentoring and reviews, Business value measurement.