Machine Learning

  • Data and Machine Learning
  • 40 questions

What this round is for

Machine learning interviews rarely test whether you can fit a model - that part is a few lines and the libraries are excellent. They test whether you can construct an evaluation you can believe.

So the questions concentrate on metrics, leakage, validation strategy and what happens after deployment. The recurring theme is that the most dangerous result is the one that looks too good.

The questions

Answer each one out loud before you open it. An answer you have read is not an answer you can give under pressure, which is the only kind that counts.

Q1 What is machine learning, as distinct from ordinary programming?

Show the answer Hide the answer

You supply examples and an algorithm finds the rules, rather than writing the rules yourself.

The goal is generalisation to unseen data. A model that reproduces its training set perfectly has achieved nothing a lookup table could not.

What it is really testing. Whether you name generalisation rather than describing the fitting process.

Q2 When should you not use machine learning?

Show the answer Hide the answer

When the rule can be written down.

A model learning 'reject orders over the credit limit' from ten thousand examples is worse than an if-statement: harder to audit, harder to change, occasionally wrong.

What it is really testing. Whether you are willing to say a model is the wrong tool.

Q3 Why can a model with 99% accuracy be useless?

Show the answer Hide the answer

Because the classes are imbalanced and the majority class alone achieves nearly that.

If two in a thousand transactions are fraudulent, predicting 'legitimate' always scores 99.8% and catches no fraud.

What it is really testing. Whether you can produce the imbalance example unprompted.

Q4 What do precision and recall each measure?

Show the answer Hide the answer

Precision is how many of the flagged cases were real; recall is how many real cases were caught.

Low precision means false alarms that cost investigation effort; low recall means misses that cost whatever the missed thing costs.

What it is really testing. Whether you can map each to a real-world cost.

Q5 How do you choose between precision and recall?

Show the answer Hide the answer

By what the errors cost, which is a business decision rather than a technical one.

Cancer screening favours recall because a miss is catastrophic; automatic account blocking favours precision because a false positive is visible and expensive.

What it is really testing. Whether you treat it as a business decision rather than a metric choice.

Q6 What is the F1 score and when is it inadequate?

Show the answer Hide the answer

The harmonic mean of precision and recall - inadequate when the two errors have different costs.

It implicitly weights them equally, which is almost never true in practice, so it hides the decision rather than making it.

What it is really testing. Whether you know its implicit assumption about equal costs.

Q7 What is a confusion matrix good for?

Show the answer Hide the answer

Showing all four outcomes rather than collapsing them into one number.

It is the first thing to look at on any classification problem, because it reveals which kind of error the model is making.

What it is really testing. Whether you look at it before any single-number metric.

Q8 What is AUC and what does it not tell you?

Show the answer Hide the answer

The probability that a random positive is ranked above a random negative - it says nothing about calibration or threshold.

A model can have excellent AUC and produce probabilities that are systematically wrong, which matters when you act on the number.

What it is really testing. Whether you know it says nothing about calibration.

Q9 Why establish a baseline first?

Show the answer Hide the answer

Because a score has no meaning without one.

Eighty-five per cent accuracy is a verdict only when you know guessing gets eighty-four. A surprising number of production models never beat theirs.

What it is really testing. Whether you establish one as a matter of routine.

Q10 What is data leakage?

Show the answer Hide the answer

Information unavailable at prediction time entering the training data.

It is the most common serious mistake in applied machine learning, and its signature is a result that looks implausibly good.

What it is really testing. Whether you recognise the implausibly-good signature.

Q11 What are common forms of leakage?

Show the answer Hide the answer

Features computed after the outcome, scaling fitted before splitting, random splits of time series, duplicate rows.

All of them look innocent in code, which is why the discipline must be structural rather than based on noticing.

What it is really testing. Whether you can list several forms rather than one.

Q12 How do you prevent leakage structurally?

Show the answer Hide the answer

Split first, then fit every transformation on the training data only, inside a pipeline.

Cross-validation then refits the whole chain per fold, so the scaler never sees the validation data.

What it is really testing. Whether your answer is structural rather than based on vigilance.

Q13 What is overfitting and how do you detect it?

Show the answer Hide the answer

The model has learned noise - detected by a large gap between training and validation performance.

That single comparison directs most of the decisions that follow, which is why it is the first diagnostic.

What it is really testing. Whether you name the train-validation gap as the diagnostic.

Q14 What is underfitting?

Show the answer Hide the answer

The model lacks the capacity or the features to learn the pattern, so it performs poorly on both sets.

It is easier to spot and easier to fix than overfitting, which is the one that reaches production looking good.

What it is really testing. Whether you know which of the two is more dangerous in practice.

Q15 What is regularisation?

Show the answer Hide the answer

A penalty on model complexity during training, discouraging it from fitting noise.

L1 drives some coefficients to zero and so selects features; L2 shrinks them all. Both trade a little bias for a lot of variance reduction.

What it is really testing. Whether you can distinguish L1 and L2 by what they do.

Q16 What is the bias-variance tradeoff?

Show the answer Hide the answer

Bias is error from wrong assumptions; variance is sensitivity to the particular training sample.

Simple models have high bias, complex ones high variance, and total error is minimised somewhere between rather than at either end.

What it is really testing. Whether you can explain why the optimum is between the extremes.

Q17 Why is a single train-test split insufficient?

Show the answer Hide the answer

Because the estimate has variance - split differently and the number moves.

Cross-validation averages over several splits and also tells you how much the result depends on which rows landed where.

What it is really testing. Whether you mention the variance of the estimate itself.

Q18 How must a time series be split?

Show the answer Hide the answer

Chronologically, never randomly.

A random split lets the model learn from the future, which is both leakage and a guarantee that the offline result will not survive deployment.

What it is really testing. Whether you know a random split is leakage, not just suboptimal.

Q19 How must grouped data be split?

Show the answer Hide the answer

By group, so no group appears in both sets.

Several readings from one patient or sessions from one user let the model recognise the group rather than learn the pattern.

What it is really testing. Whether you have thought about grouped data at all.

Q20 How many times should you use the test set?

Show the answer Hide the answer

Once, at the end.

Checking it, changing something and checking again is fitting to it. That is what the validation set exists to absorb.

What it is really testing. Whether you treat the test set as spent once used.

Q21 Why do features usually matter more than the algorithm?

Show the answer Hide the answer

Because a feature encodes domain knowledge the model cannot discover from a raw column.

Hour of day and day of week beat a raw timestamp; distance to the nearest branch beats an address. Three good features usually beat a different model.

What it is really testing. Whether you can give concrete feature examples.

Q22 What is feature scaling and which models need it?

Show the answer Hide the answer

Putting features on a comparable range - needed by distance-based and gradient-based methods.

Trees do not care because they split on thresholds. Scaling before splitting is a classic leakage route.

What it is really testing. Whether you know tree-based models do not need it at all.

Q23 How do you encode categorical variables?

Show the answer Hide the answer

One-hot for low cardinality, target or ordinal encoding for high cardinality, with care.

Target encoding leaks unless computed within folds, which makes it one of the easiest ways to produce an impressive and false result.

What it is really testing. Whether you know target encoding leaks unless done within folds.

Q24 How do you handle class imbalance?

Show the answer Hide the answer

Class weights, resampling, or choosing a threshold - and always an appropriate metric.

Oversampling before splitting duplicates rows across both sets, which is leakage dressed as a remedy.

What it is really testing. Whether you know oversampling before splitting is leakage.

Q25 Why is logistic regression still worth knowing?

Show the answer Hide the answer

It is fast, calibrated, interpretable and a strong baseline on many problems.

Coefficients give a readable account of direction and magnitude, which matters where a decision must be explained.

What it is really testing. Whether you value calibration and interpretability, not just accuracy.

Q26 Why are gradient-boosted trees the usual default for tabular data?

Show the answer Hide the answer

They handle mixed types, need little preprocessing, capture non-linearity and are hard to beat.

Deep learning generally performs worse on structured tables while needing far more data and time.

What it is really testing. Whether you know deep learning is usually worse on tables.

Q27 What is the difference between bagging and boosting?

Show the answer Hide the answer

Bagging trains models independently on samples and averages; boosting trains sequentially on previous errors.

Bagging mainly reduces variance; boosting reduces bias and can overfit if run too long without early stopping.

What it is really testing. Whether you connect each to bias or variance.

Q28 How does a random forest reduce overfitting?

Show the answer Hide the answer

By averaging many decorrelated trees, each on a random subset of rows and features.

The feature subsetting is what decorrelates them, which is why it is more than simple bagging.

What it is really testing. Whether you mention feature subsetting rather than just averaging.

Q29 What is cross-validation actually estimating?

Show the answer Hide the answer

How the modelling procedure will perform on unseen data, not how one fitted model will.

That distinction matters because the final model is usually refitted on everything, and the estimate applies to the process.

What it is really testing. Whether you know it evaluates a procedure rather than a fitted model.

Q30 How should you search hyperparameters?

Show the answer Hide the answer

Random search over sensible ranges, usually better than an exhaustive grid for the same budget.

Parameters are not equally important, and a grid spends equal effort on the one that barely matters.

What it is really testing. Whether you know why random search often beats a grid.

Q31 What should hyperparameters be tuned against?

Show the answer Hide the answer

A validation set or cross-validation - never the test set.

Tuning against the test set, even indirectly through repeated checking, inflates the final estimate.

What it is really testing. Whether you keep the test set out of the loop entirely.

Q32 What typically gives a bigger improvement than tuning?

Show the answer Hide the answer

Better features, more data, or fixing a leak.

Tuning usually buys a small gain. Reaching for it before exhausting those is a common misallocation of effort.

What it is really testing. Whether you prioritise features and data over tuning.

Q33 What is distribution shift?

Show the answer Hide the answer

The incoming data stops resembling the training data, so performance degrades silently.

No error is raised. Monitoring input distributions catches it earlier than waiting for labels to arrive.

What it is really testing. Whether you know it degrades silently with no error raised.

Q34 What is training-serving skew?

Show the answer Hide the answer

A feature computed one way in training and slightly differently in production.

Both pipelines work, which is why it is so hard to detect. A shared transformation artefact is the structural fix.

What it is really testing. Whether you know both pipelines appear to work correctly.

Q35 What is a feedback loop in a deployed model?

Show the answer Hide the answer

The model changes the behaviour it predicts, so future training data is its own output.

A recommender promoting popular items makes them more popular, and the next model learns from that distortion.

What it is really testing. Whether you can give a concrete example of the loop.

Q36 How do you monitor a model when labels arrive late?

Show the answer Hide the answer

Watch the input distributions and the prediction distribution rather than accuracy.

Waiting for ground truth can mean weeks of degraded performance before anyone notices.

What it is really testing. Whether you monitor inputs rather than waiting for labels.

Q37 Why does removing a sensitive attribute not make a model fair?

Show the answer Hide the answer

Other features correlate with it and the model reconstructs what you removed.

Postcode with ethnicity, purchase patterns with gender, employment gaps with caring responsibilities.

What it is really testing. Whether you know proxies reconstruct the removed attribute.

Q38 Why can you not satisfy every fairness definition at once?

Show the answer Hide the answer

They are mathematically incompatible in general except in degenerate cases.

So choosing one is a value judgement, and making it explicitly is better than letting the default optimisation choose.

What it is really testing. Whether you know the definitions are mutually incompatible.

Q39 What is model interpretability and when is it required?

Show the answer Hide the answer

Being able to explain why a prediction was made - required wherever a decision affects someone's life.

A slightly less accurate model you can explain is sometimes the correct engineering choice, and reflexive accuracy-maximising forgets that.

What it is really testing. Whether you accept a lower score for explainability where it is required.

Q40 What should you document about a model before deploying it?

Show the answer Hide the answer

What it predicts, what it was trained on, which metric and why, and the conditions it should not be used in.

The last is the one with the most value and least precedent, because models get reused for purposes nobody validated.

What it is really testing. Whether you document the conditions for not using it.

Two things worth doing in the room

  • Ask what the errors cost before choosing a metric. It converts a technical question into the business question it actually is, and interviewers notice.
  • If a scenario produces a surprisingly strong result, say leakage out loud and name where you would look. That instinct is worth more than any validation technique.