Interview prep

25 machine learning interview questions, with answers.

The questions that come up again and again in ML engineer and data scientist interviews, answered the way an interviewer hopes to hear: clearly, briefly, and with the trade-off.

Interviewers rarely want a textbook definition. They want to know whether you understand when a method works, when it fails and what you'd do about it. Read each question, answer it out loud before opening the answer, then compare.

These 25 are a free sample. SchoolWhool's Foundations of AI course includes 650+ interview questions, each placed right after the lesson it tests, plus a mock interview with Gaurav.

Interview questions by topic

Going deeper on one tool or subject? Each page has 20 to 30 questions with answers.

28 scikit-learn interview questions, with answers

The scikit-learn questions interviewers actually ask: the estimator API, pipelines and leakage, cross-validation, tuning, and the practical traps that separate people who've used it from people who've read about it.

24 Jupyter interview questions, with answers

Jupyter Notebook and JupyterLab questions for data roles: kernels, hidden state, magics, environments, version control and when a notebook should become real code.

24 NumPy interview questions, with answers

NumPy interview questions on arrays, dtypes, views and copies, broadcasting, vectorisation and linear algebra: the foundations every data science library is built on.

26 pandas interview questions, with answers

pandas interview questions on indexing, cleaning, groupby, merges, reshaping and performance, including the warnings and silent bugs interviewers love to ask about.

23 data visualization interview questions, with answers

Data visualization interview questions with answers: choosing the right chart, honest design, matplotlib, seaborn and plotly, and the plots that matter when you build and evaluate models.

26 probability interview questions, with answers

Probability interview questions for data science and quant roles, with worked answers: conditional probability and Bayes, distributions, expectation, the classic puzzles, and where probability shows up in machine learning.

28 Python interview questions, with answers

Python interview questions for data science, ML and backend roles: mutability, data structures, functions and scope, classes, generators, errors and the GIL, with the pitfalls interviewers probe.

Fundamentals

What's the difference between supervised and unsupervised learning?
Supervised learning trains on examples with known answers (labels) to predict those answers for new data: regression for numbers, classification for categories. Unsupervised learning has no labels and looks for structure, such as clusters or a lower-dimensional representation.
What is overfitting, and how do you detect it?
Overfitting is when a model fits the noise in its training data and does worse on new data. You detect it by comparing training and validation performance: a large gap means overfitting. Learning curves make it visible as data size grows.
Explain the bias–variance trade-off.
Bias is error from overly simple assumptions; variance is error from sensitivity to the specific training sample. More flexible models reduce bias but increase variance. You look for the complexity that minimises error on unseen data, using validation scores.
What's the difference between a parameter and a hyperparameter?
Parameters, like regression weights or tree split points, are learned from the data during training. Hyperparameters, like the learning rate, regularisation strength or tree depth, are chosen before training, usually with cross-validation.
Why do we need a separate test set if we already use cross-validation?
Cross-validation is used to make choices: features, models, hyperparameters. Every choice fits the validation data a little. The test set, touched once at the end, gives an estimate that none of those choices has influenced.

Evaluation and metrics

When is accuracy a bad metric?
When classes are imbalanced or mistakes have different costs. If 98% of cases are negative, predicting negative for everything scores 98% and is useless. Use precision, recall, the confusion matrix, or a cost-based metric instead.
Explain precision and recall to a non-technical manager.
Precision: when the model raises an alarm, how often is it right? Recall: of all the real problems, how many did it catch? Turning the sensitivity up catches more problems but raises more false alarms.
What does an AUC of 0.5 mean? And 0.9?
AUC is the probability that the model scores a random positive above a random negative. 0.5 is no better than random ranking; 0.9 means it ranks a positive above a negative 90% of the time. It says nothing about a specific threshold.
How would you evaluate a model for a rare event, like fraud at 0.2%?
Use a stratified split so both sets contain fraud, report precision and recall (or the precision–recall curve) on the fraud class, compare against simple rules, and pick a threshold from the cost of missed fraud versus manual reviews.
Which regression metric would you use: MAE or RMSE?
MAE treats all errors equally and is easy to explain. RMSE punishes large errors more, so use it when big misses are especially costly. Report the one that matches the business cost, and compare it with a simple baseline such as predicting the mean.

Models

How does linear regression find its weights?
It chooses the weights that minimise the sum of squared errors. That can be solved exactly with linear algebra (the normal equation) or iteratively with gradient descent, which scales better to large datasets.
Why is it called logistic regression if it does classification?
It models the log-odds of the positive class as a linear function of the features, which is a regression on the log-odds. The sigmoid then converts that into a probability, and a threshold turns it into a class.
How does a random forest reduce overfitting compared with a single tree?
Each tree is trained on a bootstrap sample of rows and considers a random subset of features at each split, so the trees make different errors. Averaging their predictions cancels much of the variance while keeping the low bias of deep trees.
What's the difference between bagging and boosting?
Bagging trains many models independently on resampled data and averages them, mainly reducing variance (random forests). Boosting trains models in sequence, each focusing on the previous ones' errors, mainly reducing bias (gradient boosting).
How does k-nearest neighbours make a prediction, and what are its weaknesses?
It finds the k training examples closest to the new point and takes a majority vote or average. It's sensitive to feature scale, slow at prediction time on large data, and struggles with many features because distances become less meaningful.

Data and features

How do you handle missing values?
First find out why they're missing, because the pattern can be informative. Options include dropping, imputing with a median or a model, or adding a "was missing" indicator. Imputation must be fitted on training data only, inside a pipeline.
What is data leakage? Give two examples.
Information that wouldn't exist at prediction time leaks into training or validation. Examples: scaling on the full dataset before splitting, and using a feature recorded after the outcome, such as a "refund issued" flag in a churn model.
How would you encode a categorical feature with 10,000 values?
One-hot encoding would create 10,000 sparse columns. Alternatives: group rare categories into "other", use target encoding with care (fitted within folds to avoid leakage), use hashing, or learn embeddings.
Do you always need to scale features?
No. Distance-based models, regularised linear models and anything trained by gradient descent need it. Tree-based models split on thresholds and are unaffected by monotonic scaling.
How would you split time-series data for validation?
By time, never randomly: train on earlier data and validate on later data. Walk-forward validation repeats this with a moving cut-off to mimic how the model will be used.

Production and judgement

Your model's offline metrics are great but it performs poorly in production. Why?
Common causes are leakage in the offline evaluation, differences between training and serving features, a validation split that didn't reflect real use (random instead of by time), and drift since training.
What would you monitor for a deployed model?
Input feature distributions, prediction distributions, data quality (missing values, schema changes), latency and errors, and actual performance once labels arrive. Set alerts on the ones that matter for the decision.
When should you not use machine learning?
When a simple rule works well enough, when there isn't enough reliable data, when the cost of mistakes is too high without human review, or when nobody can act on the predictions.
What is model calibration and when does it matter?
A calibrated model's probabilities match observed frequencies. It matters when the probability itself drives a decision, such as pricing, risk limits or expected-value calculations, not only the ranking.
Walk me through how you'd approach a new ML problem.
Clarify the decision and how success will be measured, check the data and define the label, build the simplest baseline, set up honest validation, iterate on features and models, choose a threshold from costs, and plan monitoring before launch.

First Principles, the SchoolWhool newsletter

One machine learning idea, explained properly, every week.

The intuition, the common mistake, and a five-minute way to try it yourself. Written by Gaurav.

Practise all 650+, lesson by lesson.