Skip to content
RED SAGSkills

Machine Learning interview questions and answers

Machine learning interview questions check whether you can choose a model, train it without leaking data and judge whether it is actually good.

Below are 60 Machine Learning questions with the correct answer and a short explanation, grouped from fresher to experienced level. Try each one before you open the answer.

What Machine Learning interviews usually check

  • ✓Supervised vs unsupervised learning
  • ✓Bias, variance, overfitting and regularisation
  • ✓Train, validation and test splits, and data leakage
  • ✓Metrics: precision, recall, F1, ROC-AUC and RMSE
  • ✓Feature engineering and imbalanced data

Machine Learning interview questions for freshers easy

1. Which model needs feature scaling

One feature is "salary" (range 10,000 to 5,000,000) and another is "age" (range 18 to 70). Which model is most affected if you do NOT scale these features?

  1. A.Decision tree
  2. B.Random forest
  3. C.k-nearest neighbours
  4. D.Gradient boosted trees
Show answer

Answer: C. k-nearest neighbours

k-NN uses distances between points, so a feature with a huge range (salary) dominates the distance and age is almost ignored. Tree-based models split on thresholds one feature at a time, so they are not affected by feature scale.

2. k-nearest neighbours vote

A k-NN classifier with k = 3 finds these nearest training points, sorted by distance: 0.5 (cat), 0.7 (dog), 0.9 (dog), 1.1 (cat), 1.2 (cat). What does it predict?

  1. A.cat
  2. B.dog
  3. C.It is a tie, so no prediction
  4. D.cat, since cat is most common among all five
Show answer

Answer: B. dog

With k = 3 only the three closest points vote: cat, dog, dog. Dog wins two votes to one. The fourth and fifth points are ignored, which shows how the choice of k can change the answer.

3. Dropout after eval()

What does this PyTorch code print?

import torch
drop = torch.nn.Dropout(p=0.5)
drop.eval()
x = torch.ones(4)
print(drop(x))
  1. A.tensor([0.5000, 0.5000, 0.5000, 0.5000])
  2. B.A random mix of 0. and 2. values
  3. C.tensor([0., 0., 0., 0.])
  4. D.tensor([1., 1., 1., 1.])
Show answer

Answer: D. tensor([1., 1., 1., 1.])

In eval mode, Dropout is the identity function, so the input passes through unchanged. In train mode it would zero some elements and scale the rest by 1 / (1 - p) = 2. Forgetting eval() at inference makes predictions random.

4. Parameter or hyperparameter

Which of these is a hyperparameter rather than a learned parameter?

  1. A.The maximum depth of a decision tree
  2. B.The weights of a linear regression
  3. C.The split thresholds inside a fitted tree
  4. D.The centroids found by k-means
Show answer

Answer: A. The maximum depth of a decision tree

Hyperparameters are set before training and control how learning happens, such as max_depth, learning rate or k. Parameters are what the algorithm learns from data, such as weights, thresholds and centroids.

5. Degree-15 curve on 16 points

You fit a degree-15 polynomial to 16 noisy data points. What is the most likely outcome?

  1. A.It underfits and gives an almost straight line
  2. B.It hits nearly every point and swings wildly between them
  3. C.It gives the same result as a degree-1 fit
  4. D.It cannot be fit at all with only 16 points
Show answer

Answer: B. It hits nearly every point and swings wildly between them

A degree-15 polynomial has 16 coefficients, enough to interpolate 16 points exactly. It fits the noise and swings wildly between and beyond the points, which is classic overfitting. Regularisation or a lower degree helps.

6. What bag-of-words throws away

With a bag-of-words representation, which two reviews would look exactly the same?

  1. A."good not bad" and "bad not good"
  2. B."good" and "very good"
  3. C."bad" and "not bad at all"
  4. D."good food" and "good service"
Show answer

Answer: A. "good not bad" and "bad not good"

Bag-of-words only counts which words appear and how often, ignoring order. Both reviews contain one "good", one "not" and one "bad", so their vectors match even though their meanings are opposite. N-grams or sequence models keep some order.

7. A movie that is several genres

Each movie can be tagged with any number of genres: action, comedy, drama and so on. What kind of problem is this?

  1. A.Multiclass classification
  2. B.Binary classification
  3. C.Ordinal regression
  4. D.Multi-label classification
Show answer

Answer: D. Multi-label classification

Multiclass means exactly one class per example. Multi-label means each example can have several labels at once, usually modelled with one sigmoid output (or binary classifier) per label instead of a single softmax.

8. Why stratify the folds

Only 3% of loan applications in your data are fraudulent. Why use StratifiedKFold instead of plain KFold?

  1. A.It makes training faster on each fold
  2. B.Each fold keeps about the same 3% fraud rate
  3. C.It removes duplicate rows between folds
  4. D.It balances classes to 50/50 in each fold
Show answer

Answer: B. Each fold keeps about the same 3% fraud rate

With rare classes, plain random folds can end up with very few or no positives, which makes scores noisy or undefined. Stratification keeps the class ratio similar in every fold. It does not rebalance the classes.

9. MAPE by hand

Forecasts were 110 (actual 100) and 180 (actual 200). What is the MAPE?

  1. A.15%
  2. B.5%
  3. C.10%
  4. D.20%
Show answer

Answer: C. 10%

Percentage errors are |110 − 100| / 100 = 10% and |180 − 200| / 200 = 10%. Their mean is 10%. MAPE takes absolute values, so the over- and under-forecast do not cancel.

10. R-squared by hand

On a validation set, the residual sum of squares is 20 and the total sum of squares around the mean is 100. What is R²?

  1. A.0.2
  2. B.0.8
  3. C.5
  4. D.0.25
Show answer

Answer: B. 0.8

R² = 1 − SS_res / SS_tot = 1 − 20/100 = 0.8. The model explains 80% of the variance compared with always predicting the mean.

11. Top-5 accuracy

An image model scores 72% top-1 accuracy and 91% top-5 accuracy. What does top-5 accuracy measure?

  1. A.Accuracy measured on the 5 most common classes
  2. B.Average accuracy over 5 random training seeds
  3. C.Accuracy on the 5% of images with top confidence
  4. D.How often the true label is in the 5 top-scored classes
Show answer

Answer: D. How often the true label is in the 5 top-scored classes

Top-k accuracy counts a prediction as correct if the true class is among the k highest-scoring classes. It is useful when many classes are similar or when a short list is shown to a user.

12. First number to compare against

A new churn model gets 92% accuracy. 91% of customers do not churn. What baseline should you report alongside it?

  1. A.A random model: 50% accuracy
  2. B.The training accuracy of the same model
  3. C.The accuracy of a perfect model: 100%
  4. D.Always predicting "no churn": 91% accuracy
Show answer

Answer: D. Always predicting "no churn": 91% accuracy

The majority-class baseline needs no model and already gets 91%, so 92% is only a small gain. Simple baselines (majority class, last value, a basic logistic regression) show whether a complex model adds real value.

13. Score versus tree depth

As max_depth increases, training score keeps rising but validation score peaks at depth 6 and then falls. Which depth should you pick?

  1. A.The largest depth tried
  2. B.Depth 1
  3. C.Any depth; they are equivalent
  4. D.About 6
Show answer

Answer: D. About 6

Below the peak the model underfits; above it the model overfits, and validation score falls even though training score rises. Choose the depth with the best validation score, or a slightly simpler one if scores are close.

14. Reporting cross-validation results

Five CV folds give AUC 0.81, 0.83, 0.74, 0.82 and 0.80. What is the most informative way to report this?

  1. A.Only the best fold, which is 0.83
  2. B.Mean and standard deviation over folds
  3. C.Only the worst fold, which is 0.74
  4. D.Only the first fold, since folds are random
Show answer

Answer: B. Mean and standard deviation over folds

The mean (0.80) summarises expected performance and the spread shows how stable it is. The 0.74 fold is worth investigating, but reporting one fold alone is either optimistic or pessimistic.

15. Checking a 90% prediction interval

A model gives 90% prediction intervals for delivery time. On 1,000 test orders, 720 actual times fall inside their intervals. What does this show?

  1. A.The intervals are too wide
  2. B.The intervals are well calibrated
  3. C.The point predictions are biased upward
  4. D.The intervals are too narrow
Show answer

Answer: D. The intervals are too narrow

A well-calibrated 90% interval should contain about 900 of 1,000 outcomes. Only 72% coverage means the model is overconfident and its intervals should be wider. Coverage near 99% would suggest they are too wide.

16. Precision from a confusion matrix

A classifier gives TP = 40, FP = 10, FN = 20, TN = 130. What is its precision?

  1. A.0.67
  2. B.0.80
  3. C.0.85
  4. D.0.20
Show answer

Answer: B. 0.80

Precision = TP / (TP + FP) = 40 / 50 = 0.80: of everything flagged positive, 80% was really positive. Recall would be 40 / 60 = 0.67 and accuracy would be 170 / 200 = 0.85, which are common mix-ups.

17. High accuracy on rare events

Only 1% of transactions are fraud. A model that predicts "not fraud" for every transaction scores 99% accuracy. What is the main problem?

  1. A.It catches every fraud case
  2. B.It has zero recall on the fraud class
  3. C.It is overfitting the training data
  4. D.Its precision on fraud is 99%
Show answer

Answer: B. It has zero recall on the fraud class

The model never predicts fraud, so it catches none of the fraud cases and its recall for that class is zero. Accuracy looks great only because the negative class dominates. For imbalanced problems, use recall, precision, F1 or PR-AUC instead.

18. High train score, low validation score

A model reaches 99% accuracy on training data but only 70% on validation data. What is most likely happening?

  1. A.Underfitting
  2. B.Good generalisation
  3. C.Overfitting
  4. D.Too much regularisation
Show answer

Answer: C. Overfitting

A large gap between training and validation performance means the model has memorised noise in the training data. Fixes include more data, simpler models, stronger regularisation and early stopping. Underfitting would show poor scores on both sets.

19. Data used to tune hyperparameters

Which dataset should be used to choose hyperparameters such as learning rate or tree depth?

  1. A.The validation set
  2. B.The test set
  3. C.The training set only
  4. D.Live production traffic
Show answer

Answer: A. The validation set

Hyperparameters are chosen by comparing scores on a validation set (or with cross-validation). The test set must stay untouched until the end, otherwise its score is no longer an honest estimate. Pipelines should enforce this split so it cannot be skipped by accident.

20. What training-serving skew is

What is training-serving skew?

  1. A.The model is trained on more data than it serves
  2. B.Serving uses a bigger machine than training
  3. C.Features are computed differently in training than in production, so the model sees different inputs
  4. D.The model is served in a different region
Show answer

Answer: C. Features are computed differently in training than in production, so the model sees different inputs

If training computes a feature in SQL and serving re-implements it in Java, small differences in rounding, time zones or defaults change the inputs. The model then behaves worse than offline tests suggested. Sharing one feature definition, for example through a feature store, prevents this.

Machine Learning intermediate interview questions medium

21. Handling class imbalance

You train a churn classifier where only 5% of users churn. Which approach is a sound first step?

  1. A.Delete all churned users so the model is not confused
  2. B.Use class weights (or resampling on the training set only) and tune the decision threshold on validation data
  3. C.Oversample the minority class before splitting into train and test
  4. D.Report accuracy and stop there
Show answer

Answer: B. Use class weights (or resampling on the training set only) and tune the decision threshold on validation data

Class weights or resampling help the model pay attention to the rare class, and tuning the threshold lets you choose the precision/recall trade-off. Resampling must happen after the split and only on training data, otherwise duplicated rows leak into the test set.

22. Which regularisation gives sparse weights

You want a linear model that automatically sets many feature weights to exactly zero. Which regularisation should you use?

  1. A.L2 (ridge) regularisation
  2. B.Dropout
  3. C.Batch normalisation
  4. D.L1 (lasso) regularisation
Show answer

Answer: D. L1 (lasso) regularisation

The L1 penalty has a sharp corner at zero, so the optimum often lands exactly on zero for weak features, giving sparse models and built-in feature selection. L2 shrinks weights towards zero but rarely makes them exactly zero.

23. F1 score from a confusion matrix

A fraud model has TP = 40, FP = 10, FN = 20 and TN = 130. What is its F1 score?

  1. A.0.67
  2. B.0.73
  3. C.0.80
  4. D.0.85
Show answer

Answer: B. 0.73

Precision is 40 / 50 = 0.80 and recall is 40 / 60, about 0.667. F1 is their harmonic mean: 2 * 0.8 * 0.667 / (0.8 + 0.667), about 0.73. The harmonic mean sits closer to the weaker of the two numbers.

24. NDCG for a three-item ranking

A search returns three results with relevance 1, 0, 1 in that order. Using gain = relevance and discount 1 / log2(position + 1), what is NDCG@3?

  1. A.0.50
  2. B.0.67
  3. C.0.81
  4. D.0.92
Show answer

Answer: D. 0.92

DCG = 1/1 + 0/log2(3) + 1/log2(4) = 1 + 0 + 0.5 = 1.5. The ideal order 1, 1, 0 gives IDCG = 1 + 1/log2(3), about 1.631. NDCG = 1.5 / 1.631, about 0.92. Putting the second relevant item lower costs only a little.

25. Loss for logistic regression

Why is logistic regression trained with log loss (cross-entropy) rather than mean squared error on the sigmoid output?

  1. A.MSE cannot be computed for values between 0 and 1
  2. B.Log loss needs no gradient to be minimised
  3. C.MSE always gives the same weights but slower
  4. D.Log loss with a sigmoid is convex in the weights; MSE is not
Show answer

Answer: D. Log loss with a sigmoid is convex in the weights; MSE is not

Combining the sigmoid with log loss gives a convex objective with a single global minimum and well-behaved gradients. MSE through a sigmoid is non-convex and gives tiny gradients when the model is confidently wrong. Log loss is also the negative log-likelihood of a Bernoulli model.

26. Rows left out of a bootstrap

Each tree in a random forest is trained on a bootstrap sample of n rows drawn with replacement from n rows. For large n, roughly what fraction of the original rows are left out of a given tree (out-of-bag)?

  1. A.About 50%
  2. B.About 10%
  3. C.About 37%
  4. D.About 63%
Show answer

Answer: C. About 37%

The chance a row is never picked in n draws is (1 − 1/n)ⁿ, which tends to 1/e ≈ 0.368. So about 37% of rows are out-of-bag for each tree and about 63% are in the sample. The OOB rows give a free validation estimate.

27. What bagging and boosting each reduce

Broadly, which statement about bagging and boosting is right?

  1. A.Bagging mainly cuts bias; boosting mainly cuts variance
  2. B.Both only reduce training time
  3. C.Bagging mainly cuts variance; boosting mainly cuts bias
  4. D.Both need models that are trained in sequence
Show answer

Answer: C. Bagging mainly cuts variance; boosting mainly cuts bias

Bagging averages many high-variance models trained in parallel on resampled data, which smooths out their errors. Boosting trains weak, high-bias learners in sequence, each fixing what the previous ones got wrong, which reduces bias.

28. Why k-means++ is used

Running k-means twice with random starting centres gives quite different clusters. What does k-means++ initialisation do to help?

  1. A.Picks spread-out starting centres
  2. B.Finds the best value of k automatically
  3. C.Guarantees the global optimum every time
  4. D.Removes outliers before the clustering starts
Show answer

Answer: A. Picks spread-out starting centres

k-means only finds a local optimum that depends on the starting centres. k-means++ picks each new centre with probability proportional to its squared distance from the nearest chosen centre, which spreads them out. It usually gives better, more stable results, and running several initialisations helps further.

29. Encoding hour of day

A demand model uses hour of day as a number 0–23, so 23 and 0 look far apart even though they are one hour apart. What is a common fix for a linear or distance-based model?

  1. A.Divide the hour by 24 to scale it
  2. B.Take the logarithm of the hour value
  3. C.Sort the training rows by hour first
  4. D.Add sin(2π·h/24) and cos(2π·h/24) features
Show answer

Answer: D. Add sin(2π·h/24) and cos(2π·h/24) features

Mapping the hour onto a circle with sine and cosine makes 23:00 and 00:00 close together, matching reality. Dividing by 24 only rescales the same jump. Tree models can also handle hour with splits or one-hot encoding.

30. MAPE on low-selling products

You report MAPE for a demand forecast. Many products sell 0 or 1 unit on some days. What goes wrong?

  1. A.MAPE ignores errors on the low sellers
  2. B.MAPE turns negative for small values
  3. C.MAPE gives the same value as MAE
  4. D.Errors explode or are undefined at tiny actuals
Show answer

Answer: D. Errors explode or are undefined at tiny actuals

MAPE divides each error by the actual value, so actuals of 0 make it undefined and actuals of 1 make small misses look like 100%+ errors. Alternatives include weighted MAPE (total absolute error / total actuals) or MASE.

31. Which class gets confused

Rows are true labels and columns are predictions. What is the recall for class "refund"?

            billing  refund  other
billing        80      15      5
refund         30      60     10
other           5       5     90
  1. A.0.75
  2. B.0.80
  3. C.0.60
  4. D.0.30
Show answer

Answer: C. 0.60

Recall for refund = correct refund predictions / all true refunds = 60 / (30 + 60 + 10) = 0.60. Precision for refund would use the column: 60 / (15 + 60 + 5) = 0.75. The matrix also shows refunds are often mistaken for billing.

32. MRR across three queries

For three queries, the first relevant result appears at ranks 1, 2 and 4. What is the mean reciprocal rank?

  1. A.About 0.43
  2. B.About 2.33
  3. C.About 0.75
  4. D.About 0.58
Show answer

Answer: D. About 0.58

Reciprocal ranks are 1/1, 1/2 and 1/4 = 1, 0.5 and 0.25. Their mean is 1.75 / 3 ≈ 0.583. MRR only looks at the first relevant item, which suits tasks like FAQ search with one right answer.

33. Better offline, flat online

A new recommender raises offline NDCG by 4%, but an A/B test shows no change in orders. What is the most reasonable reading?

  1. A.The A/B test setup must be broken somehow
  2. B.NDCG gains always show up in order counts
  3. C.Offline metrics are proxies; trust the test
  4. D.Orders are not a valid metric to look at
Show answer

Answer: C. Offline metrics are proxies; trust the test

Offline data reflects past behaviour under the old system, and NDCG may not capture what drives orders. A well-run A/B test measures the real effect. The gap is a reason to revisit the offline metric, not to ignore the experiment.

34. Negative scores from cross_val_score

Why does this print negative numbers?

scores = cross_val_score(reg, X, y, cv=5, scoring='neg_mean_squared_error')
print(scores)  # e.g. [-412.3 -398.1 -455.0 -401.7 -420.9]
  1. A.The model is predicting negative values
  2. B.Scorers are maximised, so losses are negated
  3. C.MSE turns negative when the model is poor
  4. D.The folds were not shuffled before splitting
Show answer

Answer: B. Scorers are maximised, so losses are negated

scikit-learn's scorers follow "higher is better", so error metrics are returned as negatives. Negate them to get MSE: about 418 on average here. The sign has nothing to do with the predictions.

35. Precision and recall at 0.6

Six cases have (score, true label): (0.9, 1), (0.8, 0), (0.7, 1), (0.5, 1), (0.4, 0), (0.2, 0). At threshold 0.6, what are precision and recall?

  1. A.Precision 0.67, recall 1.0
  2. B.Precision 0.67, recall 0.67
  3. C.Precision 1.0, recall 0.67
  4. D.Precision 0.5, recall 0.5
Show answer

Answer: B. Precision 0.67, recall 0.67

Predicted positive (score ≥ 0.6): 0.9, 0.8, 0.7, of which 2 are true, so precision = 2/3. There are 3 actual positives (0.9, 0.7, 0.5) and 2 were caught, so recall = 2/3. The 0.5 case is a false negative.

36. Reading a MASE of 0.8

A demand forecast has mean absolute scaled error (MASE) of 0.8. What does this mean?

  1. A.It is 80% accurate
  2. B.80% of forecasts are within 1 unit
  3. C.Its MAE is 80% of the naive forecast's MAE
  4. D.It is 20% worse than the naive forecast
Show answer

Answer: C. Its MAE is 80% of the naive forecast's MAE

MASE divides the model's MAE by the MAE of a naive forecast (such as last period's value) on the training data. Below 1 means it beats the naive method; above 1 means it is worse. It works even when actuals include zeros.

37. Which prediction hurts log loss most

Each pair is (true label, predicted probability of class 1). Which single prediction adds the most to log loss?

  1. A.(1, 0.6)
  2. B.(0, 0.3)
  3. C.(0, 0.9)
  4. D.(1, 0.05)
Show answer

Answer: D. (1, 0.05)

Log loss for one example is -ln of the probability given to the true class. These are -ln(0.6) = 0.51, -ln(0.7) = 0.36, -ln(0.1) = 2.30 and -ln(0.05) = 3.00. Confident wrong predictions are punished very hard, which is why log loss rewards good calibration.

38. Why a forest beats one tree

Why does a random forest usually generalise better than a single deep decision tree?

  1. A.Averaging many decorrelated trees reduces variance
  2. B.Each tree in the forest is deeper and more accurate
  3. C.Random forests remove bias completely
  4. D.Random forests do not need training data
Show answer

Answer: A. Averaging many decorrelated trees reduces variance

A single deep tree has low bias but high variance: small data changes produce very different trees. A forest trains trees on bootstrap samples with random feature subsets, so their errors are less correlated, and averaging them cuts variance. Bias stays roughly the same.

39. Unseen category at predict time

A OneHotEncoder fitted on training cities raises an error when a new city appears in production. What setting avoids the crash?

  1. A.sparse_output=False always
  2. B.drop="first" on the encoder
  3. C.dtype=float on the encoder
  4. D.handle_unknown="ignore"
Show answer

Answer: D. handle_unknown="ignore"

By default OneHotEncoder raises on unseen categories. handle_unknown="ignore" encodes them as all zeros, and "infrequent_if_exist" maps them to the infrequent bucket. Also monitor how often unknown values occur.

40. Precision moved, AUC did not

With a fixed 0.5 threshold, precision fell sharply this month, but AUC is unchanged. What is a likely explanation?

  1. A.Scores shifted, so the fixed cut lands elsewhere
  2. B.AUC must be wrong because precision has fallen
  3. C.The model has stopped ranking cases correctly
  4. D.Precision does not depend on the threshold used
Show answer

Answer: A. Scores shifted, so the fixed cut lands elsewhere

Threshold metrics like precision and recall depend on where the cut sits in the score distribution. A score shift or a change in base rate can move them while ranking quality (AUC) holds. Recalibration or threshold re-tuning may be enough.

Machine Learning interview questions for experienced candidates hard

41. ROC-AUC after calibration

You apply isotonic-style monotonic calibration that changes probabilities but keeps the order of scores the same (no new ties). What happens to ROC-AUC?

  1. A.It always increases
  2. B.It always decreases
  3. C.It becomes undefined
  4. D.It stays the same, because ROC-AUC depends only on the ranking of scores
Show answer

Answer: D. It stays the same, because ROC-AUC depends only on the ranking of scores

ROC-AUC equals the probability that a random positive gets a higher score than a random negative, so it only depends on ordering. A strictly monotonic transform keeps ordering, so AUC is unchanged while calibration metrics like Brier score and log loss can improve. Note that isotonic regression can create ties, which may change AUC slightly.

42. L2 penalty versus AdamW

Why is AdamW preferred over adding an L2 penalty to the loss when using Adam?

  1. A.AdamW does not use momentum, so it is more stable
  2. B.With Adam, L2 gradients get rescaled by the adaptive learning rate, so the penalty is uneven; AdamW applies weight decay directly to the weights, decoupled from the gradient
  3. C.AdamW removes the need for a learning rate
  4. D.L2 penalties are not differentiable
Show answer

Answer: B. With Adam, L2 gradients get rescaled by the adaptive learning rate, so the penalty is uneven; AdamW applies weight decay directly to the weights, decoupled from the gradient

In SGD, L2 regularisation and weight decay are equivalent. In Adam, the L2 term passes through the per-parameter adaptive scaling, so weights with large gradient history are regularised less. AdamW decouples decay from the gradient update, giving more consistent regularisation and better generalisation.

43. A feature that is too good

Your churn model reaches 0.99 AUC. The most important feature is "days_since_last_support_ticket_closed", and many churned users have a final ticket titled "cancel account". What is the most likely issue?

  1. A.The model is excellent and ready to ship
  2. B.The feature should be one-hot encoded
  3. C.The AUC is low because of class imbalance
  4. D.Target leakage: the feature contains information created by the churn event itself
Show answer

Answer: D. Target leakage: the feature contains information created by the churn event itself

The feature includes tickets raised as part of cancelling, which happens at or after churn, so it will not be available when you need to predict. Build features only from data before a fixed prediction time and check suspicious top features for leakage.

44. Target after label smoothing

With nn.CrossEntropyLoss(label_smoothing=0.1) and 5 classes, what target probability does the true class effectively get?

  1. A.0.90
  2. B.0.98
  3. C.0.80
  4. D.0.92
Show answer

Answer: D. 0.92

PyTorch mixes the one-hot target with a uniform distribution: (1 − ε) × 1 + ε / K = 0.9 + 0.1/5 = 0.92. Each wrong class gets 0.1/5 = 0.02. This discourages overconfident logits and often helps calibration.

45. kNN with 2,000 features

kNN worked well with 10 features but performs badly after you add 2,000 sparse features. What is the main reason?

  1. A.In high dimensions distances become similar, so "nearest" means little
  2. B.kNN cannot store more than 1,000 features
  3. C.Extra features always make the data linearly separable
  4. D.k must be at least the number of features
Show answer

Answer: A. In high dimensions distances become similar, so "nearest" means little

As dimensions grow, the gap between the nearest and farthest neighbour shrinks relative to the distances themselves, so neighbours stop being meaningfully close. Many irrelevant features also add noise to every distance. Feature selection or dimensionality reduction usually helps.

46. RBF kernel with a huge gamma

An RBF-kernel SVM has gamma set very high. Training accuracy is near 100% but validation accuracy is poor. Why?

  1. A.Each point affects only a tiny area, so the boundary hugs points
  2. B.High gamma turns the RBF kernel into a linear one
  3. C.High gamma removes all of the support vectors
  4. D.High gamma makes the SVM ignore the training labels
Show answer

Answer: A. Each point affects only a tiny area, so the boundary hugs points

The RBF kernel is exp(−γ||x − x′||²). With a large γ, similarity drops off very fast, so each support vector affects only its close neighbourhood. The boundary becomes islands around training points, which overfits. Lower γ gives a smoother boundary.

47. Margin width of a linear SVM

A hard-margin linear SVM has weight vector w = (3, 4). What is the total width of the margin between the two supporting hyperplanes w·x + b = ±1?

  1. A.0.2
  2. B.0.4
  3. C.5
  4. D.2
Show answer

Answer: B. 0.4

The distance between w·x + b = 1 and w·x + b = −1 is 2 / ||w||. Here ||w|| = √(9 + 16) = 5, so the margin is 2/5 = 0.4. The SVM maximises this by minimising ||w||.

48. One long straggly cluster

Agglomerative clustering with single linkage merges two obvious groups into one long cluster because a thin trail of points connects them. Which linkage is less prone to this?

  1. A.Single linkage with more points
  2. B.Any linkage, after shuffling rows
  3. C.Single linkage with Manhattan distance
  4. D.Ward or complete linkage
Show answer

Answer: D. Ward or complete linkage

Single linkage measures the distance between the closest pair of points, so one chain of nearby points can link distant groups (chaining). Complete linkage uses the farthest pair and Ward minimises within-cluster variance, both of which favour compact clusters.

49. Weight given by class_weight balanced

A training set has 1,000 rows: 900 negatives and 100 positives. scikit-learn's class_weight="balanced" sets weight = n_samples / (n_classes × n_samples_in_class). What weight does each positive row get?

  1. A.5.0
  2. B.9.0
  3. C.0.1
  4. D.10.0
Show answer

Answer: A. 5.0

For positives: 1000 / (2 × 100) = 5.0. For negatives: 1000 / (2 × 900) ≈ 0.556. The weights make each class contribute equally to the total loss; 9.0 is the raw ratio of negatives to positives, which is not this formula.

50. Macro F1 with a weak minority class

Class A (900 samples) has F1 = 0.90 and class B (100 samples) has F1 = 0.50. What is the macro-averaged F1?

  1. A.0.70
  2. B.0.86
  3. C.0.90
  4. D.0.50
Show answer

Answer: A. 0.70

Macro F1 is the plain mean of per-class F1: (0.90 + 0.50) / 2 = 0.70. It treats each class equally, so a weak minority class pulls it down. The support-weighted F1 would be 0.9 × 0.9 + 0.1 × 0.5 = 0.86.

51. A metric using all four cells

Why is the Matthews correlation coefficient (MCC) often recommended for imbalanced binary problems?

  1. A.It uses all four cells; high only if both classes do well
  2. B.It ignores true negatives, like F1 does
  3. C.It always lies between 0 and 1, like accuracy
  4. D.It equals accuracy whenever data is balanced
Show answer

Answer: A. It uses all four cells; high only if both classes do well

MCC is a correlation between predicted and true labels, from −1 to +1, using TP, TN, FP and FN. A model that predicts only the majority class gets MCC 0 even with 99% accuracy. F1 ignores true negatives, which MCC does not.

52. Calibrating with only 300 rows

You must calibrate a classifier using a held-out set of only 300 rows. Why is Platt (sigmoid) scaling often safer than isotonic regression here?

  1. A.Isotonic overfits small data; Platt fits two parameters
  2. B.Isotonic regression cannot output probabilities
  3. C.Platt scaling changes the ranking and so lifts AUC
  4. D.Isotonic needs the full training data again to fit
Show answer

Answer: A. Isotonic overfits small data; Platt fits two parameters

Isotonic regression fits a free-form monotonic step function and needs plenty of data to avoid overfitting. Platt scaling fits a logistic curve with just two parameters, which is stable on small sets but less flexible. With thousands of rows, isotonic often wins.

53. Choosing features before cross-validating

With 10,000 random features and 100 rows, you pick the 50 most correlated with the label using all rows, then run 5-fold CV and get 90% accuracy. Labels are actually random. Why?

  1. A.Selection saw validation labels, so CV is optimistic
  2. B.Five folds are too few for 100 rows
  3. C.Correlation is the wrong selection method
  4. D.Random labels always give 90% accuracy
Show answer

Answer: A. Selection saw validation labels, so CV is optimistic

Selecting on the full data picks features that happen to correlate with every row's label, including future validation rows. CV then confirms the lucky pattern. Feature selection must happen inside each training fold, for example inside a Pipeline.

54. Comparing two models on one test set

Models A and B are scored on the same 2,000 test rows. Which test focuses on rows where exactly one model is right?

  1. A.An unpaired two-sample t-test
  2. B.A chi-square test of independence on labels
  3. C.McNemar's test
  4. D.Kolmogorov–Smirnov on the features
Show answer

Answer: C. McNemar's test

Because both models see the same rows, results are paired. McNemar's test uses only the discordant counts (A right/B wrong versus A wrong/B right) to judge whether the difference is real. Treating the two accuracies as independent samples ignores the pairing.

55. Average prediction versus observed rate

On 10,000 recent loans, a default model's mean predicted probability is 6%, but 3% actually defaulted. AUC is unchanged from launch. What is the most likely issue and fix?

  1. A.Base rate shifted; recalibrate the intercept
  2. B.Ranking broke; retrain from scratch
  3. C.Labels leaked; drop the newest features
  4. D.Nothing; mean predictions need not match
Show answer

Answer: A. Base rate shifted; recalibrate the intercept

A stable AUC means the model still ranks borrowers well, but predictions are systematically too high: calibration-in-the-large is off. Re-fitting the intercept or a calibration map on recent data fixes probabilities without retraining the ranking.

56. Using attention maps as explanations

A product manager wants to show attention heat maps as the "reason" a model rejected a loan application. What is the main caution?

  1. A.Attention weights show where information moved, not why the decision was made
  2. B.Attention maps are always random and contain no information
  3. C.Attention can only be shown for the first layer of a model
  4. D.Heat maps reveal the model's training data, which is private
Show answer

Answer: A. Attention weights show where information moved, not why the decision was made

Attention is one step among many layers, MLPs and residual mixing, and different attention patterns can give the same output. High weight on a word does not prove that word caused the result. For decisions like credit, use proper explanation methods, tested reason codes and human review.

57. NDCG at 3 for a ranking

A search result list has relevance grades [0, 3, 2] in ranked order. Using DCG = sum of rel_i / log2(i + 1) for positions i = 1, 2, 3, what is NDCG@3 (to two decimals)?

  1. A.0.68
  2. B.0.50
  3. C.1.00
  4. D.0.85
Show answer

Answer: A. 0.68

DCG = 0/1 + 3/1.585 + 2/2 = 1.893 + 1 = 2.893. The ideal order [3, 2, 0] gives 3/1 + 2/1.585 + 0 = 4.262, so NDCG = 2.893 / 4.262 = 0.68. NDCG rewards putting the most relevant items at the top, and it is scaled so a perfect ranking scores 1.

58. SMOTE before cross-validation

A team applies SMOTE to the whole dataset, then runs 5-fold cross-validation. CV recall is far higher than in production. Why?

  1. A.SMOTE always lowers recall in production
  2. B.Cross-validation cannot be used with SMOTE at all
  3. C.Five folds are too few for an imbalanced dataset
  4. D.Synthetic points made from test rows leak into training folds
Show answer

Answer: D. Synthetic points made from test rows leak into training folds

SMOTE creates new points by interpolating between real minority rows, including rows that later land in validation folds. Resampling must happen inside each training fold only, for example with an imblearn Pipeline.

59. Computing ECE

A model has two confidence bins. Bin A: 100 predictions, mean confidence 0.9, accuracy 0.8. Bin B: 300 predictions, mean confidence 0.6, accuracy 0.6. What is the expected calibration error?

  1. A.0.05
  2. B.0.10
  3. C.0.0
  4. D.0.025
Show answer

Answer: D. 0.025

ECE is the sample-weighted average of |accuracy − confidence|. Bin A gives (100/400)×0.1 = 0.025 and bin B gives 0, so ECE = 0.025. Rising ECE in production means scores no longer mean what they say, which matters for thresholds and pricing.

60. Updating a score for a new base rate

A calibrated model trained where 10% of cases were positive outputs 0.50 for a case. The base rate is now 30%, and P(x|y) is unchanged. What is the adjusted probability?

  1. A.About 0.50
  2. B.About 0.65
  3. C.About 0.90
  4. D.About 0.79
Show answer

Answer: D. About 0.79

Under label shift, multiply the odds by the ratio of new to old prior odds: (0.3/0.7)/(0.1/0.9) ≈ 3.86. Odds of 1 become 3.86, so p = 3.86/4.86 ≈ 0.79. This lets you fix calibration without retraining.

Ready to test yourself?

Take a 15-question Machine Learning MCQ test with a score at the end, or practise the full Machine Learning question bank and earn points on the leaderboard.