Top 50 Machine Learning Interview Questions 2026
Machine learning interviews are asked of ML engineers, applied scientists, data scientists, and increasingly AI engineers and backend engineers who will own a model in production. The LLM wave did not remove the fundamentals round - it made it more important, because the people who can explain why a model with 99% accuracy is useless, or why validation looks great and production does not, are the people trusted to ship anything with a model in it.
The interviewer is testing whether you can reason about data, generalization and evaluation under pressure: spot the leak, pick the metric that matches the business cost, and say what you would check first when a model degrades. The 50 questions below escalate from fundamentals to the system design scenarios live rounds actually use.
Practice alongside this post. The same ground is drilled as timed multiple-choice in the Machine Learning question bank and the Statistics question bank, and the AI Engineering question bank covers the LLM side. For a structured path, follow the ML engineer prep track or the data scientist prep track, and if you have a target company, the Google MLE, Meta MLE and Amazon MLE prep packs are built for those loops. This post deliberately stays general; the narrower siblings are Top 50 LLM interview questions, MLOps interview questions and the complete guide to RAG interview questions.
Part 1: Fundamentals of generalization (1-8)
1. What is the bias-variance tradeoff?
Expected prediction error on unseen data decomposes (for squared loss) into three parts:
E[(y - f̂(x))²] = Bias[f̂(x)]² + Var[f̂(x)] + σ²
- Bias - error from wrong assumptions. A linear model fitted to a curved relationship is biased no matter how much data you give it.
- Variance - error from sensitivity to the particular training sample. A deep unpruned tree changes shape every time you resample the data.
- σ² - irreducible noise. No model removes it.
More flexible models lower bias and raise variance. The follow-up is usually "how do you tell which one you have?" - compare training error with validation error (question 2). The modern gotcha: very large overparameterized networks can show "double descent", where test error falls again past the interpolation point, so the classic U-curve is a useful mental model, not a law.
2. How do you diagnose overfitting versus underfitting?
Look at training and validation error together, ideally as a learning curve over training-set size or epochs.
| Pattern | Diagnosis | What to try |
|---|
| Train error high, val error high, close together | Underfitting (high bias) | More features, a more flexible model, less regularization, train longer |
| Train error low, val error much higher | Overfitting (high variance) | More data, regularization, simpler model, early stopping, augmentation |
| Both low, close together | Good fit | Check the test set once, then ship |
Look at the gap, not either number alone. "Get more data" only helps the variance case.
3. What do L1 and L2 regularization do, and when would you pick each?
Both add a penalty on weight size to the loss:
L2 (ridge): loss + λ Σ wᵢ²
L1 (lasso): loss + λ Σ |wᵢ|
L2 shrinks all weights smoothly toward zero but rarely makes any exactly zero; it handles correlated features by spreading weight across them. L1 drives some weights to exactly zero, so it doubles as feature selection, but with correlated features it tends to pick one arbitrarily. Elastic net combines both.
The geometric explanation interviewers like: the L1 constraint region is a diamond with corners on the axes, so the loss contours usually touch it at a corner where some coordinates are zero. The L2 region is a circle with no corners. Follow-up: features must be on the same scale before regularizing, or the penalty punishes features merely for having small units.
4. How does dropout work, and what happens at inference time?
During training, dropout zeroes each activation with probability p independently on every forward pass, so the network cannot rely on any single unit and learns redundant representations. It behaves roughly like training an ensemble of thinned networks that share weights.
At inference dropout is turned off. To keep expected activations the same, modern frameworks use "inverted dropout": surviving activations are scaled by 1/(1-p) during training, so nothing needs rescaling at test time.
model.train()
model.eval()
The classic bug: forgetting model.eval() before evaluation, which makes validation metrics noisy between runs.
5. Why do you need separate train, validation and test sets?
- Train - fits the parameters.
- Validation - chooses hyperparameters, features, architecture and the early-stopping point.
- Test - estimates performance on unseen data, touched once at the end.
Every decision made on a set's score leaks that set into the model: tune against test 50 times and its score is optimistic. The split must also mirror production: if the model will predict next month from past data, split by time; if it will meet new users, split by user so no user appears in both train and test. A random row split for either case gives you a number you cannot trust.
6. What is data leakage? Give three examples.
Leakage is when the training data contains information that will not be available at prediction time, so offline metrics look far better than production.
- Target leakage - a feature computed from the label or after it. Predicting churn with "account closed date", or predicting a diagnosis with a treatment code that is only issued after diagnosis.
- Preprocessing leakage - fitting a scaler, imputer, encoder or feature selector on the full dataset before splitting, so validation statistics flow into training.
- Temporal / group leakage - random splits on time-series data (the model sees the future), or the same patient, user or session appearing in both train and test.
The tell in an interview scenario: a suspiciously high score (AUC 0.99 on a hard problem). The fix for preprocessing leakage is to put every fitted step inside a pipeline so it is fit only on the training fold:
from sklearn.pipeline import make_pipeline
pipe = make_pipeline(StandardScaler(), LogisticRegression())
cross_val_score(pipe, X, y, cv=5)
Split the data into k folds, train on k-1, validate on the held-out fold, rotate k times and average. It uses every row for validation once and gives a variance estimate across folds, which a single split cannot.
Variants you should name:
- Stratified k-fold - keeps the class ratio in each fold; the default for imbalanced classification.
- Group k-fold - keeps all rows from one group (user, patient) in the same fold.
- Time-series split - expanding or rolling window where validation is always after training (
TimeSeriesSplit in scikit-learn).
- Nested CV - an inner loop tunes hyperparameters, an outer loop estimates performance, so tuning does not bias the estimate.
Skip it when training is very expensive - use one held-out set.
8. What is the curse of dimensionality?
As the number of features grows, the volume of the space grows exponentially, so a fixed amount of data becomes sparse. Consequences: distances between points concentrate (nearest and farthest neighbors end up similarly far away), which hurts k-NN and clustering; the number of samples needed to cover the space explodes; and models have more room to fit noise.
Mitigations: feature selection, regularization, dimensionality reduction. Follow-up: "then why do deep nets work on images?" - real data lies near a much lower-dimensional manifold, and convolution and attention exploit that structure.
Part 2: Metrics and evaluation (9-16)
9. Define precision, recall and F1. When does each matter?
From the confusion matrix (TP, FP, FN, TN):
precision = TP / (TP + FP) # of the things I flagged, how many were right
recall = TP / (TP + FN) # of the real positives, how many did I catch
F1 = 2 · P · R / (P + R)
Precision matters when false positives are expensive - blocking a legitimate payment, sending a spam label on a real email. Recall matters when false negatives are expensive - missing a cancer, missing fraud. F1 is the harmonic mean, so it is dragged down by whichever is worse; use it when you need one number and both errors matter roughly equally. If they do not matter equally, use F-beta (beta > 1 weights recall) or, better, put actual costs on FP and FN and optimize expected cost.
10. Why is accuracy misleading on imbalanced data?
With 1% positives, a model that always predicts "negative" scores 99% accuracy and catches nothing. Accuracy weights every row equally, so the majority class dominates. Report per-class precision and recall, PR-AUC, or a cost-weighted metric instead, and always compare against the trivial baseline.
11. ROC-AUC versus PR-AUC - when do you use which?
ROC plots true positive rate against false positive rate across thresholds; ROC-AUC is the probability that a random positive is scored above a random negative. PR plots precision against recall.
| ROC-AUC | PR-AUC (average precision) |
|---|
| Baseline for a random model | 0.5 | The positive rate (e.g. 0.01) |
| Sensitive to class imbalance | Barely - FPR divides by the large negative count | Strongly |
| Best for | Balanced-ish data, ranking quality overall | Rare positives where you care about the top of the list |
With 1 fraud per 1,000 transactions, a model can post a ROC-AUC of 0.95 while precision at any useful recall is poor, because a small FPR on a huge negative pool is still many false alarms. PR-AUC shows that. Neither tells you which threshold to deploy - that is a business decision on the curve.
12. What does it mean for a model to be calibrated, and how do you fix calibration?
A classifier is calibrated when its scores mean what they say: of all the cases scored 0.7, about 70% are positive. A model can rank perfectly (high AUC) and still be badly calibrated. It matters whenever the score is used as a probability - expected-value decisions, bidding in ads, combining model outputs, or showing a risk score to a human.
Check it with a reliability diagram (bin by predicted probability, plot observed rate) and summarize with Brier score or expected calibration error. Fix it with a post-hoc mapping fitted on held-out data:
- Platt scaling - a logistic regression on the scores; good for small data, sigmoid-shaped miscalibration.
- Isotonic regression - a monotone step function; more flexible, needs more data.
- Temperature scaling - one scalar dividing the logits; the standard for neural nets.
Gotcha: resampling or class weights for imbalance (question 15) distort probabilities, so recalibrate afterwards.
13. How do you choose a classification threshold?
Not 0.5 by default. The threshold converts a score into an action, so pick it from the costs: with cost c_FP of a false positive and c_FN of a false negative, and calibrated probabilities, flag when p > c_FP / (c_FP + c_FN). In practice you also face constraints - "precision must be at least 90%" or "the review team can handle 500 cases a day" - so you pick the point on the PR curve that satisfies the constraint and maximizes the other metric. Choose the threshold on validation data, never on test, and revisit it when the base rate shifts in production.
14. Which regression metrics do you know, and how do they differ?
- MSE / RMSE - squares errors, so outliers dominate; RMSE is in the target's units. Optimizing MSE predicts the conditional mean.
- MAE - linear in error, robust to outliers; optimizing it predicts the conditional median.
- MAPE - percentage error; breaks when actuals are near zero and penalizes over-prediction and under-prediction asymmetrically.
- R² - share of variance explained relative to predicting the mean; can be negative on test data, and is not comparable across datasets.
The metric encodes what you care about: when under-stocking costs more than over-stocking, a quantile (pinball) loss beats any symmetric metric.
15. How do you handle class imbalance?
In rough order of what to try:
- Use the right metric first - PR-AUC, recall at fixed precision, or expected cost. Many "imbalance problems" are metric problems.
- Class weights - weight the minority class higher in the loss (
class_weight="balanced" in scikit-learn, scale_pos_weight in XGBoost). Cheap and usually enough.
- Resampling - undersample the majority (fast, loses data) or oversample the minority (risks overfitting duplicates). SMOTE synthesizes minority points by interpolation; it helps less than people expect on high-dimensional or tabular data with categorical features.
- Threshold tuning on the PR curve (question 13).
- Focal loss for deep models - down-weights easy examples.
- Reframe - anomaly detection when positives are extremely rare or keep changing shape.
Gotchas: resample only inside the training fold, never before splitting, and recalibrate probabilities afterwards because both weighting and resampling shift them.
16. Offline metrics look great but the online A/B test is flat. Why?
The most common causes:
- The offline metric is a proxy that does not track the business metric (AUC on clicks while the goal is retention).
- Leakage or a split that does not match production inflated the offline number (question 6).
- Training-serving skew - features computed differently online, missing, stale or defaulted.
- Feedback loops / selection bias - the logged data came from the old model's choices, so offline evaluation only covers what the old model showed.
- The change is too small to detect - the test is underpowered.
- Novelty or position effects in the experiment itself.
Debug in order: production features match training, the offline gain holds on a recent time-based holdout, the experiment has power, then question the proxy.
Part 3: Classical models (17-26)
17. What are the assumptions of linear regression, and what breaks when they fail?
- Linearity of the relationship between features and target - violated, predictions are biased.
- Independent errors - violated (time series, clustered data), standard errors are too small.
- Homoscedasticity (constant error variance) - violated, coefficients are still unbiased but confidence intervals are wrong.
- Normally distributed errors - matters for small-sample inference, not for prediction.
- No perfect multicollinearity - with strong but imperfect collinearity, coefficients become unstable and hard to interpret even though predictions may be fine.
Most assumptions matter for inference (coefficients, p-values), much less for prediction. Check with residual plots and variance inflation factors.
18. How does logistic regression work, and why not use MSE for it?
It models the log-odds as linear in the features and squashes through a sigmoid:
p(y=1|x) = σ(wᵀx + b) = 1 / (1 + e^-(wᵀx + b))
loss = -[y log p + (1-y) log(1-p)] # log loss / binary cross-entropy
Log loss is the negative log-likelihood of a Bernoulli model, and combined with the sigmoid it is convex in the weights, so gradient methods find the global optimum. MSE on a sigmoid is non-convex. Each coefficient is a change in log-odds per unit of the feature, so e^w is an odds ratio. It is linear in the features, so interactions must be engineered in.
19. How does a decision tree choose a split?
At each node it tries candidate features and thresholds and picks the split that most reduces impurity, weighted by child size. For classification the impurity is Gini (1 - Σ pₖ²) or entropy (-Σ pₖ log pₖ, reduction = information gain); for regression it is variance (MSE). The search is greedy - it does not look ahead - and it continues until a stopping rule (max depth, minimum samples per leaf, minimum impurity decrease).
Trees need no scaling and handle interactions natively. Their weakness is variance: small data changes produce a different tree - exactly what ensembles fix.
20. Random forest versus gradient boosting - how do they differ?
| Random forest | Gradient boosting (XGBoost, LightGBM) |
|---|
| How trees combine | Independent deep trees, averaged (bagging) | Shallow trees added sequentially, each fitting the previous ensemble's errors |
| Mainly reduces | Variance | Bias |
| Randomness | Bootstrap rows + random feature subset per split | Learning rate, row/column subsampling |
| Overfits with more trees? | Rarely - more trees just stabilize | Yes - needs early stopping on validation |
| Tuning effort | Low, good defaults | Higher (learning rate, depth, trees, regularization) |
| Parallel training | Trees in parallel | Trees sequential (split-finding parallelized) |
On tabular data, a tuned gradient boosting model is usually the strongest baseline. Random forest is the safer quick baseline and gives a free out-of-bag error estimate.
21. What does the learning rate do in gradient boosting?
Each new tree's contribution is multiplied by the learning rate (shrinkage) before being added. A smaller rate means each tree corrects less, so you need more trees, but the ensemble generalizes better because no single tree dominates. The standard recipe is to set a small learning rate, set a large number of trees, and let early stopping on a validation set pick the count:
model = xgb.XGBClassifier(n_estimators=5000, learning_rate=0.03,
max_depth=6, early_stopping_rounds=100)
model.fit(X_tr, y_tr, eval_set=[(X_val, y_val)])
Learning rate and tree count trade off, so tune them together.
22. How would you explain feature importance, and what are the traps?
- Impurity-based importance (the default in tree libraries) is biased toward high-cardinality and continuous features and is computed on training data.
- Permutation importance - shuffle one feature on held-out data and measure the drop in score. Model-agnostic, but correlated features share credit, so both can look unimportant.
- SHAP values - additive per-prediction attributions based on Shapley values; consistent and good for explaining individual predictions, but still an explanation of the model, not of the world.
The trap interviewers probe: importance is not causation. A feature can be important because it is a proxy for something else, or because it leaks the label.
23. How does k-means work, and what are its limits?
Pick k centroids, assign each point to the nearest centroid, recompute centroids as cluster means, repeat until assignments stop changing. It minimizes within-cluster sum of squares and converges to a local optimum, so use k-means++ initialization and several restarts.
Limits: you choose k (elbow, silhouette, or the downstream use); it assumes roughly spherical, similar-sized clusters; it is sensitive to scale and outliers. Alternatives: DBSCAN for arbitrary shapes and noise, Gaussian mixtures for soft, elliptical clusters.
24. What is PCA, and when would you use it?
PCA finds orthogonal directions of maximum variance in the data (the eigenvectors of the covariance matrix, or equivalently via SVD of the centered data) and projects onto the top k. Uses: compression, visualization, removing collinearity.
Gotchas: standardize features first or the largest-unit feature dominates; it is linear, so curved structure needs kernel PCA, UMAP or an autoencoder; components are hard to interpret; and the directions of highest variance are not necessarily the ones most predictive of the target. Fit PCA on training data only - fitting it on everything is preprocessing leakage (question 6).
25. Explain the difference between generative and discriminative models.
A discriminative model learns p(y|x) or a decision boundary directly - logistic regression, SVMs, most neural classifiers. A generative model learns how the data is produced, p(x|y) and p(y) (or p(x) alone), and can classify via Bayes' rule - Naive Bayes, Gaussian mixtures, and in the broader sense language models and diffusion models.
Discriminative models usually win on accuracy with enough data. Generative models can do well with little data (Naive Bayes is a strong small-text baseline) and can sample new data. Follow-up: Naive Bayes works despite its false independence assumption because its probabilities are badly calibrated but its class ranking is often still right.
26. What is the difference between bagging and boosting, and where does stacking fit?
Bagging trains many models in parallel on bootstrap samples and averages them; it reduces variance and suits high-variance learners like deep trees. Boosting trains models sequentially, each focusing on the errors of the ensemble so far; it reduces bias and suits weak learners like shallow trees. Stacking trains a meta-model on the out-of-fold predictions of diverse base models; it can squeeze out extra accuracy but is fragile and harder to serve.
The follow-up: stacking must use out-of-fold predictions for the meta-model's training data, or the meta-model learns from base models that have already seen those rows - a leakage bug.
Part 4: Features and embeddings (27-31)
27. How do you encode categorical features?
- One-hot - one column per category. Fine for low cardinality and linear models; explodes for high cardinality.
- Ordinal / label encoding - integers. Only correct when categories are ordered, though tree models tolerate it.
- Target (mean) encoding - replace the category with the mean target. Powerful for high cardinality, but it leaks unless computed out-of-fold with smoothing toward the global mean.
- Hashing - hash categories into a fixed number of buckets; bounded memory, handles unseen categories, accepts collisions.
- Learned embeddings - a dense vector per category trained with the model; the standard for very high cardinality (user IDs, item IDs) in deep models.
Plan an "unknown" bucket - production will send unseen categories.
28. When do you need to scale features?
Scale for distance- or gradient-based methods: k-NN, k-means, SVMs, PCA, regularized linear models, and neural networks. Tree-based models do not need it because splits are invariant to monotone transformations.
Standardization (zero mean, unit variance) is the usual default; min-max scaling bounds values to a range but is sensitive to outliers; a log transform tames heavy-tailed features like income or counts. Fit the scaler on training data only and apply the same fitted transform at serving time - mismatched scaling between training and serving is a classic source of training-serving skew.
29. How do you handle missing values?
First ask why they are missing. If missingness carries signal (no income reported, no previous purchase), add a missing-indicator feature - often more predictive than any imputed value. Options:
- Drop rows or columns - only when the missing share is small and random.
- Simple imputation (median, mode, a constant) plus an indicator.
- Model-based imputation (k-NN, iterative imputation) - better estimates, more complexity.
- Let the model handle it - XGBoost and LightGBM learn a default direction for missing values at each split.
Fit imputers inside the training fold, and make serving fill a missing feature the same way training did.
30. What is an embedding, and how are embeddings learned?
An embedding maps a discrete or high-dimensional object (a word, a user, a product, an image) to a dense low-dimensional vector where geometric closeness reflects similarity for the task. Embeddings are learned as a by-product of a training objective: word2vec predicts nearby words, two-tower recommenders put users and the items they engage with close together, contrastive models (like CLIP for image and text) pull matching pairs together and push non-matching pairs apart, and transformer encoders produce contextual embeddings.
Similarity is cosine or dot product; search over millions of vectors uses approximate nearest neighbor indexes (HNSW, IVF). Gotcha: embeddings from different models are not comparable, so a new embedding model means re-embedding the corpus. Retrieval itself is covered in the RAG interview guide.
31. How do you approach feature engineering for a new problem?
Start from domain mechanics, not from the columns. For fraud: velocity (transactions per card in the last hour), deviation from the user's own baseline, account age, devices shared across cards. For time series: lags, rolling statistics, calendar features.
Then the discipline: every feature must be computable at prediction time from data available then (point-in-time correctness), and the same code should produce it offline and online - which is the main argument for a feature store, covered in the MLOps interview questions.
Part 5: Optimization and neural networks (32-40)
32. Compare batch, stochastic and mini-batch gradient descent.
All three update w ← w - η ∇L(w); they differ in how many examples estimate the gradient.
- Batch - the whole dataset per step. Exact gradient, smooth convergence, one step per epoch - impractical for big data.
- Stochastic (SGD) - one example per step. Very noisy, which can help escape poor regions, but slow to settle.
- Mini-batch - typically 32 to a few thousand examples. Uses GPU parallelism, gradient noise is moderate, and it is what everyone means by "SGD" in practice.
Larger batches mean fewer updates per epoch; a common heuristic scales the learning rate with batch size and adds warmup.
33. What do momentum, RMSProp and Adam add?
- Momentum keeps an exponentially weighted average of past gradients, so updates build speed in consistent directions and damp oscillation across ravines.
- RMSProp divides each parameter's step by a running average of its squared gradients, giving per-parameter adaptive learning rates.
- Adam combines both: a first-moment (momentum) and second-moment (RMSProp) estimate, with bias correction for the early steps. The common defaults are learning rate 1e-3, β₁ = 0.9, β₂ = 0.999.
AdamW decouples weight decay from the gradient update, which matters because L2 regularization inside Adam's adaptive scaling does not behave like true weight decay; AdamW is the standard for training transformers. A known nuance: well-tuned SGD with momentum sometimes generalizes better than Adam on vision tasks.
34. Explain backpropagation.
Backpropagation is the chain rule applied efficiently over the computation graph. The forward pass computes and caches every intermediate value; the backward pass starts from ∂L/∂output and walks the graph in reverse, multiplying each node's local derivative by the upstream gradient to get the gradient of the loss with respect to every parameter in one pass.
For one layer z = Wx + b, a = f(z):
∂L/∂z = ∂L/∂a ⊙ f'(z)
∂L/∂W = ∂L/∂z · xᵀ
∂L/∂x = Wᵀ · ∂L/∂z # passed to the previous layer
It costs a small constant multiple of the forward pass. Follow-up: the cached activations are most of training memory - gradient checkpointing recomputes them instead to save memory.
35. Why do we need nonlinear activations, and how do ReLU, sigmoid and GELU compare?
Without a nonlinearity, any stack of linear layers collapses into one linear layer, so depth adds nothing.
| Activation | Range | Pros | Cons |
|---|
| Sigmoid | (0, 1) | Probability output | Saturates, gradient max 0.25, not zero-centered |
| Tanh | (-1, 1) | Zero-centered | Still saturates |
ReLU max(0, x) | [0, ∞) | Cheap, no saturation for x > 0 | "Dead" units stuck at 0 |
| Leaky ReLU | (-∞, ∞) | Avoids dead units | Extra hyperparameter |
| GELU / SiLU | smooth | Smooth, default in transformers | Slightly more compute |
36. What causes vanishing and exploding gradients, and how are they fixed?
Backprop multiplies one Jacobian per layer. If those factors are mostly below 1 (saturating sigmoids, small weights), the gradient shrinks exponentially with depth and early layers stop learning; if mostly above 1, it blows up and training diverges with NaNs. Plain RNNs suffer most because they multiply the same matrix at every time step.
Fixes:
- ReLU-family activations instead of saturating ones.
- Careful initialization - Xavier/Glorot for tanh, He/Kaiming for ReLU - to keep activation variance stable.
- Residual connections - the identity path gives gradients a direct route back, the key idea that made very deep networks trainable.
- Normalization layers (question 37).
- Gradient clipping for exploding gradients.
- Gated architectures (LSTM, GRU) for recurrent models, and attention, which replaced recurrence for most sequence work.
37. What does batch normalization do, and how does layer norm differ?
Batch norm normalizes each feature to zero mean and unit variance across the mini-batch, then applies a learned scale and shift. It allows higher learning rates, makes training less sensitive to initialization, and adds mild regularization from batch noise. At inference it uses running averages of mean and variance collected during training - which is why model.eval() matters.
It depends on batch size and is awkward for variable-length sequences. Layer norm normalizes across the features of each single example, so it ignores batch size and behaves identically in training and inference - why transformers use layer norm (or RMSNorm).
38. What loss functions would you use for different tasks?
- Regression - MSE (mean, outlier-sensitive), MAE (median, robust), Huber (MSE near zero, MAE in the tails), quantile loss for prediction intervals.
- Binary classification - binary cross-entropy (log loss); focal loss for heavy imbalance.
- Multi-class - softmax plus categorical cross-entropy; label smoothing to curb overconfidence.
- Ranking - pointwise (cross-entropy per item), pairwise (BPR, hinge on pairs), listwise (LambdaRank-style, optimizing NDCG-like objectives).
- Embeddings / retrieval - contrastive losses (InfoNCE with in-batch negatives), triplet loss.
The loss should match how the output is used; it is often a differentiable proxy for the metric you report.
39. How does a convolutional neural network differ from a fully connected network?
A convolutional layer slides small learned filters across the input: each output sees only a local patch, and the same weights are reused at every position. That gives far fewer parameters than a dense layer, translation equivariance, and a hierarchy from edges to parts to objects.
Follow-up: vision transformers use attention over image patches, trading CNNs' built-in locality bias for flexibility, and tend to need more data or pretraining to match them.
Each token's embedding is projected into a query, key and value. Attention scores every query against every key, normalizes with softmax, and takes a weighted sum of values:
Attention(Q, K, V) = softmax(Q Kᵀ / √d_k) V
Dividing by √d_k keeps the dot products from growing with dimension and saturating the softmax. Multi-head attention runs several of these in parallel on lower-dimensional projections so different heads can track different relationships. A block is attention plus a feed-forward network, each wrapped in a residual connection and layer norm. Because attention has no notion of order, positional information is added (sinusoidal, learned, or rotary embeddings). Decoder models apply a causal mask so a token only attends to earlier tokens.
Key tradeoff: attention is O(n²) in sequence length, which drives context-length cost. Tokenization, KV caching, fine-tuning and decoding strategies belong to the LLM round - see Top 50 LLM interview questions.
Part 6: Models in production (41-44)
41. What is data drift versus concept drift, and how do you detect them?
- Data (covariate) drift - the input distribution
p(x) changes: a new marketing channel brings different users, a sensor gets recalibrated.
- Concept drift - the relationship
p(y|x) changes: fraudsters change tactics, so the same features now mean something different.
- Label/prior shift - the base rate
p(y) changes.
Detect data drift by comparing live feature distributions with the training distribution - population stability index, KS test or Jensen-Shannon distance per feature, plus prediction-distribution monitoring. Concept drift needs labels, which arrive late, so use proxy signals meanwhile. Gotcha: with enough traffic every test fires - alert on effect size for important features, not p-values.
42. What is training-serving skew, and how do you prevent it?
It is any difference between what the model saw in training and what it gets in production: features computed by batch SQL offline but by separate service code online, mismatched preprocessing versions, features late or missing at request time, different defaults when a lookup fails.
Prevention: one feature definition for both paths (a feature store or shared library), log served features and train on those logs, version preprocessing with the model, and run parity checks. The wider lifecycle is in the MLOps interview questions post.
43. How do you roll out a new model safely?
- Offline gate - beats the current model on a recent time-based holdout and on key slices, not only overall.
- Shadow mode - the new model scores live traffic, predictions are logged but not used; compare against the incumbent and check latency and errors.
- Canary - a small share of traffic, with automatic rollback on guardrail metrics.
- A/B test - a properly powered experiment on the business metric with guardrails (latency, complaints, revenue).
- Full rollout, keeping the old model ready for instant rollback.
Offline metrics earn the right to a test; they do not replace one.
Work from the cheapest, most likely causes outward:
- Is it real? Check the monitoring pipeline and label delay - delayed labels can make recent performance look worse.
- Upstream data - schema changes, a feature that went null or constant, a broken join, a unit change. Compare feature distributions this week versus last.
- Serving - a new model version, a preprocessing change, a stale feature cache, timeouts filling in defaults.
- The world - a seasonal effect, a product launch, a new user segment (data drift); a changed adversary or behavior (concept drift).
- Slice it - by country, platform, new versus returning users. A drop concentrated in one slice points straight at the cause.
Interviewers score the order and the slicing more than the final fix.
Part 7: ML system design scenarios (45-50)
These are the questions that fill the second half of an MLE loop. Structure every answer the same way: clarify the objective and constraints, define the metric, design data and labels, pick features and a model (start with a baseline), then serving, evaluation and monitoring. The ML serving system design walkthrough and AI system design interview questions go deeper on the infrastructure side.
- Objective - define it beyond clicks: watch time, purchases, long-term retention, with diversity and freshness constraints.
- Architecture - multi-stage. Candidate generation narrows millions of items to hundreds cheaply: a two-tower model with approximate nearest neighbor search, plus collaborative filtering and trending sources. Ranking scores those with a heavier model on user-item cross features, often predicting several outcomes (click, watch, like) combined into one score. Re-ranking applies diversity, deduplication and policy rules.
- Cold start - content features and popularity for new items, onboarding signals and context for new users.
- Evaluation - offline recall@k for retrieval and NDCG for ranking on a time-based split, then A/B tests on the real objective.
- Gotchas - feedback loops (the model trains on what it chose to show), position bias, popularity bias. Exploration traffic is the remedy to name.
46. Design a real-time fraud detection system for card payments.
- Constraints - a decision within a tight latency budget at authorization time; positives are rare and labels (chargebacks) arrive weeks later.
- Features - sliding-window velocity per card, device, merchant and IP; deviation from the cardholder's baseline; graph links between cards, devices and accounts. Aggregates stream into a low-latency online store, with point-in-time-correct backfills for training.
- Model - gradient boosted trees are the usual workhorse; add rules for known patterns and hard blocks.
- Decisions - three outcomes (approve, step-up authentication, decline or review), with thresholds set from the costs of fraud loss versus false declines and review capacity.
- Evaluation - PR-AUC, recall at a fixed false-positive rate, and dollar-weighted metrics, on time-based splits.
- Gotchas - label delay, adversaries adapting (concept drift), and selection bias: declined transactions never get a label, so let a tiny random sample through to review to measure what you block.
47. Design a search ranking system.
- Stages - query understanding (spelling, intent), retrieval (BM25 plus dense embeddings, merged), learning-to-rank on a few hundred candidates, business re-ranking.
- Labels - human relevance judgments plus click logs for scale. Clicks are position-biased; correct with randomization experiments or inverse propensity weighting.
- Features - text match scores, embedding similarity, document quality and freshness, popularity, personalization.
- Model and loss - gradient boosted trees with a LambdaMART-style listwise objective are a strong standard; cross-encoder rerankers on the top results when latency allows.
- Evaluation - NDCG@k and MRR offline, then interleaving or A/B tests on success rate, time to click, reformulation rate and zero-result rate.
48. Design a model to predict customer churn.
Start by pinning down the definition, because it decides everything: for a subscription, "cancels within the next 30 days"; for a non-contractual product, "no activity for 60 days". Then build snapshots: for each customer at each reference date, compute features from data before the date and the label from the window after - this point-in-time construction is where most churn models leak.
Features: usage trend (last 4 weeks versus the prior 4), engagement breadth, support tickets, billing failures, plan and tenure. Model: logistic regression for a readable baseline, gradient boosting for performance. The real question is what happens next: a churn score is only useful if an intervention changes the outcome, so the strongest answer mentions uplift modeling - target the customers whose behavior the retention offer will actually change, not merely those most likely to leave - and measuring that with a holdout group.
49. You have 100 labeled examples and need a classifier. What do you do?
- Baseline first - a simple model on good features, or a rule. Measure it honestly with cross-validation, since a single small test set is very noisy.
- Transfer learning - use a pretrained model's embeddings as features for a small classifier (logistic regression on top of text or image embeddings is a strong, cheap start), or fine-tune lightly.
- Zero- or few-shot with an LLM for text tasks, evaluated against the 100 labels.
- Get more labels cheaply - active learning (label the examples the model is least sure about), weak supervision (labeling functions combined statistically), or LLM-assisted labeling with human spot checks.
- Augmentation where it preserves labels.
With tiny data, strong priors (pretraining, simple models, regularization) beat flexible models.
50. Design the evaluation strategy for a model before you have built it.
Often asked as "we want to predict delivery times - how will you know it works?" Answering before naming a model is a senior signal.
- Business metric and guardrails - what moves if the model is good (on-time rate, customer contacts), and what must not get worse (latency, fairness across regions).
- Offline metric that tracks it - e.g. MAE plus a quantile-based "promised time was late" rate, since being late hurts more than being early.
- Splits that mirror deployment - time-based, with new stores or regions held out if the model must generalize to them.
- Baselines - the current heuristic and a simple model; a complex model must beat both.
- Slice analysis - performance by segment, not just the average.
- Online plan - shadow, then an A/B test with a pre-registered success criterion and enough power.
- Monitoring - drift and performance dashboards, and a retraining trigger.
How to practice for a machine learning interview
- Implement the core algorithms once from scratch - linear and logistic regression with gradient descent, a decision tree split, k-means, and a two-layer network with manual backprop in NumPy. Each is under a page, and afterwards questions 18, 19, 23 and 34 stop being memorization.
- Train one model end to end on a real tabular dataset with a pipeline, a time-based split, gradient boosting, calibration and a threshold chosen from costs. Then deliberately leak a feature and watch the validation score jump.
- Say the metric before the model. In every practice scenario, state the objective, the metric and the split before naming an algorithm - interviewers notice the order.
- Drill the design scenarios out loud with the same structure every time (objective, metric, data and labels, features, model, serving, evaluation, monitoring) and a 35-minute timer.
- Keep your statistics sharp - hypothesis tests, confidence intervals, power and A/B testing come up in the same loops, especially for data scientist roles.
Keep going
- Drill it under pressure: the Machine Learning, Statistics and AI Engineering question banks, plus the free daily challenge with no account needed.
- Follow a track: the ML engineer prep track, the data scientist prep track, or the AI engineer track if your role leans toward LLM applications.
- Target a loop: the Google MLE, Meta MLE and Amazon MLE prep packs.
- Go narrower: Top 50 LLM interview questions, MLOps interview questions, the complete guide to RAG interview questions and agentic AI interview questions. For the coding round, Top 50 Python interview questions and our in-browser coding challenges.
- Pick a lane: AI engineer vs ML engineer vs MLOps - which pays more.
- Practise the follow-ups: the chat-based AI mock interview pushes back with the "and how would you know it is leaking?" questions a real ML round runs on.
- Related guides: Top 50 Data Analyst Interview Questions 2026 (SQL, Excel, Stats, BI), Top 50 Product Manager Interview Questions 2026 (With Answers).
#machinelearning #mlinterview #datascience #mlengineering #interviews #career