The short answer: machine learning interviews mix four kinds of questions. Fundamentals cover bias and variance, overfitting, regularization, validation, data leakage, evaluation metrics and common models. Coding is usually Python, sometimes implementing a simple model from scratch. ML system design asks you to turn a vague product problem into a deployed, monitored model. And a project deep dive checks what you actually built. Machine learning engineer and research roles add deep learning questions, such as backpropagation, vanishing gradients, normalization, dropout and transformers. The answers below are checked against Google’s Machine Learning Crash Course and Rules of Machine Learning, scikit-learn’s documentation and the original papers. We ran both code examples.
Interviewing for a data scientist role? Our data scientist interview questions add statistics, A/B testing and SQL. For production pipelines, see our MLOps engineer interview questions.
Machine learning fundamentals
“Explain the bias-variance trade-off.”
Error on new data comes from three places: bias (the model’s assumptions are too simple, so it underfits and is wrong on both training and validation data), variance (the model is too sensitive to the particular training set, so it overfits: low training error, high validation error) and noise you can’t remove. More flexible models lower bias and raise variance. You manage the balance with model choice, regularization, more data and ensembles: bagging mainly reduces variance, and boosting mainly reduces bias. Learning curves show which problem you have.
“What is overfitting, and how do you detect and prevent it?”
Google’s Machine Learning Crash Course defines overfitting as a model that matches, or memorizes, the training set so closely that it fails to make correct predictions on new data. You detect it when the training and validation loss curves diverge. Google lists unrepresentative training data and overly complex models as common causes. To prevent it, get more or better data, simplify the model, add regularization, stop training early when validation loss starts rising, and use dropout or data augmentation for neural networks. For trees, limit depth or require more samples per leaf.
“What’s the difference between L1 and L2 regularization?”
Both add a penalty on the weights to the loss. L2 penalizes squared weights and shrinks them toward zero, but Google notes it never pushes them all the way to zero. L1 penalizes absolute weights, and scikit-learn describes its Lasso model as able to set coefficients exactly to zero, so L1 also selects features. Elastic net combines the two. The regularization rate (lambda) sets the strength, and you tune it on validation data.
“How should you split your data?”
Use a training set to fit, a validation set (or cross-validation) to tune, and a test set you touch once at the end. If you tune on the test set, it stops being an honest estimate. Split by time when you’ll predict the future: scikit-learn’s TimeSeriesSplit always trains on earlier data than it tests on. Split by group when the same user, patient or device appears many times: GroupKFold keeps each group on one side, so the model can’t score well by memorizing individuals.
“How does k-fold cross-validation work?”
Split the data into k folds, train on k − 1 of them, validate on the one left out, rotate through all k, and average the scores. You get a more stable estimate than one split, at k times the training cost. For classifiers, scikit-learn’s cross_val_score uses stratified folds by default, which keep the class balance the same in every fold.
“What is data leakage? Give examples.”
scikit-learn defines data leakage as using information that wouldn’t be available at prediction time when building the model, which makes performance estimates overly optimistic. Common examples:
- A feature recorded after the outcome, such as “account closed date” in a churn model.
- Preprocessing fitted on all the data before splitting. scikit-learn names scaling, imputation, PCA and feature selection, and says never to include test data when you call
fitorfit_transform. - The same records on both sides, through duplicates, or the same user in training and test sets.
- A random split on time-ordered data, so the model trains on the future.
The fix is to put every preprocessing step in a pipeline that’s fitted inside each training fold. There’s a runnable example in the coding section below.
“Precision, recall or F1: which would you optimize?”
Precision is the share of predicted positives that are actually positive. Recall is the share of actual positives the model finds. F1 is their harmonic mean. Choose based on the cost of each error: a spam filter that hides real messages loses user trust, so it favors precision, while a screening test that misses a disease is worse than a false alarm, so it favors recall. Google points out that these metrics are calculated at a single classification threshold, so moving the threshold trades one for the other.
“ROC AUC or PR AUC?”
ROC AUC is the probability that the model ranks a randomly chosen positive above a randomly chosen negative, so it doesn’t depend on a threshold. Google’s course says that when classes are imbalanced, precision-recall curves may compare models better. ROC AUC can look strong when nearly every example is negative, while precision at a useful recall is still poor.
“How do you handle an imbalanced dataset?”
Start with the metric: accuracy is misleading when 99% of examples are negative. Then choose a technique:
- Downsample the majority class and upweight it. Google’s course describes this approach: downsampling balances the training batches, and upweighting reduces the prediction bias it would otherwise cause.
- Use class weights, which most libraries support.
- Tune the decision threshold for the precision and recall you need.
- Collect more minority examples, if you can.
Keep folds stratified, and resample only inside the training data, or you’ve leaked.
“Why scale features, and which models need it?”
Google’s course notes that normalization helps gradient descent converge faster, because features with very different ranges make it “bounce”, though adaptive optimizers such as Adam reduce the problem. Distance-based models (k-nearest neighbors, k-means, support vector machines with an RBF kernel) and regularized linear models need scaled features, so the penalty and distances treat every feature fairly. Tree-based models split on thresholds and don’t. Fit the scaler on training data only.
“How do you handle missing data?”
First ask why it’s missing: data missing at random is different from data missing because of the outcome. Then drop the rows or columns, impute (median, mode or a model), and consider adding a “was missing” indicator feature, since missingness itself can be predictive. Fit imputers on training data only. Some models don’t need imputation: scikit-learn’s histogram-based gradient boosting models have built-in support for missing values.
“How does logistic regression work?”
It applies the sigmoid function to a weighted sum of the features, which gives a probability between 0 and 1, and it’s trained by minimizing log loss (cross-entropy). Linear regression is a poor fit for classification because its outputs aren’t bounded probabilities. The weights are interpretable as changes in log-odds, which is why logistic regression is still a common baseline. You’ll implement it in the coding section.
“Random forest or gradient boosting?”
Google describes a random forest as an ensemble of decision trees, each trained with random noise. Each tree sees a random subset of the training examples (bagging), and each split tests a random subset of features. The trees are independent, so a forest is robust and needs little tuning. Gradient boosting builds trees one after another, each trained to predict the errors of the model so far, and shrinks each tree’s contribution, much like a learning rate. It’s often the most accurate choice on tabular data, but it needs more tuning and can overfit.
“How does k-means work, and how do you choose k?”
It assigns each point to the nearest of k centroids, moves each centroid to the mean of its points, and repeats until assignments stop changing. It minimizes within-cluster variance (inertia). scikit-learn notes that it assumes convex, roughly round clusters and handles elongated shapes poorly, and that k-means++ initialization usually beats random starts. Scale features first. Choose k with the elbow method or silhouette scores, and with whether the clusters are useful to the business.
“What does PCA do?”
Principal component analysis projects the data onto the directions of greatest variance, which are uncorrelated with each other. Use it to compress features, remove noise or plot high-dimensional data. Standardize first, since PCA is driven by variance, and fit it on training data only. The components are harder to explain than the original features.
Deep learning questions
“Explain backpropagation.”
A forward pass computes the prediction and the loss. The backward pass applies the chain rule from the output layer back to the input, computing the gradient of the loss with respect to every weight and reusing intermediate results so it’s efficient. An optimizer such as stochastic gradient descent or Adam then updates the weights in the direction that lowers the loss.
“What causes vanishing gradients, and how do you fix them?”
Google’s glossary describes the problem as gradients in early layers of deep networks becoming so small that those layers barely learn. Saturating activations like sigmoid and tanh, stacked over many layers, are a classic cause. Fixes include ReLU-family activations, careful weight initialization, normalization layers and residual connections. The ResNet paper introduced residual learning to make much deeper networks easier to optimize. For the opposite problem, exploding gradients, clip the gradient norm.
“Batch normalization or layer normalization?”
Batch normalization normalizes each layer’s inputs using statistics from the mini-batch, which its authors showed allows faster training with higher learning rates. It depends on the batch size and behaves differently in training and inference. Layer normalization computes the statistics across the features of a single example. Its paper notes it does the same computation at training and test time and applies easily to recurrent networks. The original Transformer uses layer normalization.
“What does dropout do?”
During training, dropout randomly removes units and their connections. The paper that introduced it says this prevents units from co-adapting too much, which reduces overfitting. At test time, the full network is used, which approximates averaging the predictions of many thinned networks. Higher dropout rates regularize more strongly.
“What is attention, and why did transformers replace recurrent networks?”
Attention lets each position in a sequence weigh every other position when computing its representation. “Attention Is All You Need” (2017) introduced the Transformer, built on attention alone, without recurrence or convolutions, which made training far more parallelizable than with recurrent networks. The trade-off is that self-attention’s cost grows with the square of the sequence length. Our LLM engineer interview questions go deeper on transformers, embeddings and fine-tuning.
“What is transfer learning?”
Start from a model pretrained on a large dataset and adapt it to your task, by training a new output layer on top of frozen features or by fine-tuning some or all of the weights. It works because early layers learn general features. With little data, freeze more layers and use a lower learning rate.
Questions about models in production
“What is training-serving skew?”
Google’s Rules of Machine Learning defines it as a difference between performance during training and during serving, caused by differences in how the two pipelines handle data, by data changing between training and serving, or by a feedback loop between the model and the algorithm. Its advice is to log the features used at serving time and train on those (rule 29), and to reuse code between the training and serving pipelines (rule 32).
“What’s the difference between data drift and concept drift?”
Data drift is a change in the inputs, such as new kinds of users. Concept drift is, in Google’s glossary, a shift in the relationship between the features and the label: the same inputs now mean something different, like fraud patterns after attackers adapt. Monitor input distributions, prediction distributions and, when labels arrive, model quality, and retrain on a schedule or a trigger. Our MLOps guide covers monitoring with delayed labels.
“Would you launch this without machine learning?”
Often, yes. Rule 1 of Google’s Rules of Machine Learning is not to be afraid to launch a product without machine learning, and rule 4 is to keep the first model simple and get the infrastructure right. A heuristic baseline tells you whether ML is worth it, and it’s the bar your model has to beat.
“Your model improved offline but lost the A/B test. Why?”
Check for leakage that inflated the offline score, training-serving skew, an offline metric that doesn’t match what users value, a population that has shifted since the training data was collected, and novelty or feedback effects in the test. Then compare predictions from the two pipelines on the same live traffic.
Machine learning coding questions
Implement logistic regression from scratch
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def fit(X, y, lr=0.1, steps=1000):
w = np.zeros(X.shape[1])
b = 0.0
n = len(y)
for _ in range(steps):
p = sigmoid(X @ w + b)
w -= lr * X.T @ (p - y) / n
b -= lr * np.mean(p - y)
return w, b
def predict(X, w, b):
return sigmoid(X @ w + b) >= 0.5
We ran this on Python 3.12 with NumPy 2.5 on 600 standardized synthetic examples. Its predictions matched scikit-learn’s unregularized logistic regression on every example.
The gradient of log loss with respect to the weights is X.T @ (p - y) / n, and saying that out loud is half the answer. Expect these follow-ups:
- Numerical stability:
np.exp(-z)overflows for large negativez. Usescipy.special.expitor clipz. - Regularization: for L2, add a term proportional to
wto the weight gradient, and leave the bias unpenalized. - Scale: use mini-batches for large data, and scale features first so gradient descent converges.
Show data leakage in cross-validation
import numpy as np
from sklearn.feature_selection import (
SelectKBest,
)
from sklearn.linear_model import (
LogisticRegression,
)
from sklearn.model_selection import (
cross_val_score,
)
from sklearn.pipeline import (
make_pipeline,
)
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 5000))
y = rng.integers(0, 2, size=100)
# Wrong: picks features on all rows
sel = SelectKBest(k=20)
X_leaky = sel.fit_transform(X, y)
leaky = cross_val_score(
LogisticRegression(), X_leaky, y
)
# Right: selection inside each fold
model = make_pipeline(
SelectKBest(k=20),
LogisticRegression(),
)
honest = cross_val_score(model, X, y)
print(leaky.mean(), honest.mean())
The features and labels are pure noise, so no model can beat a coin flip. On scikit-learn 1.9, the leaky version scored 0.85 accuracy and the pipeline scored 0.48. Choosing features with all the labels let the test folds’ answers into training. With 5,000 features and 100 rows, some features correlate with the labels by chance.
Other coding questions to practice:
- Compute precision, recall and a confusion matrix without a library.
- Implement k-means.
- Split a dataset by user so no user appears in both training and test sets.
Our Python interview questions cover the language itself.
ML system design interview questions
ML system design questions give you an open problem, such as “detect spam” or “rank a feed”, and watch how you structure it. A framework that works for most prompts:
- Clarify the goal. Which product metric matters, and what does each kind of error cost?
- Ask whether you need ML. Propose a simple baseline first, as Google’s rules 1 and 4 advise.
- Define the data and labels. Where do labels come from, how noisy and delayed are they, and what could leak?
- Choose features and a model. Start simple, such as logistic regression or gradient boosting, and add complexity only when it pays.
- Evaluate offline. Use a metric that matches the cost of errors, on a split that matches how you’ll predict (often by time).
- Serve and test online. Choose batch or real-time scoring, set a latency budget, and run an A/B test.
- Monitor and iterate. Watch drift, skew and feedback loops, and plan retraining.
Worked example: “Design a spam filter for direct messages”
- Goal: cut the spam people see without hiding real messages. False positives cost more than misses here, so aim for high precision at an acceptable recall.
- Baseline: rate limits and rules for obvious abuse, such as brand-new accounts sending the same link to hundreds of people.
- Labels: user spam reports, which are noisy, delayed and only cover messages people saw, plus a sample labeled by reviewers.
- Features: account age and history, sending rate, how many recipients know the sender, links and their reputation, and a text representation of the message.
- Model: gradient boosting on behavior features first, then a small text model if it adds precision.
- Offline evaluation: precision at a fixed recall on a time-based split, checked by segment, such as new users and languages.
- Serving: score each message before delivery, so latency matters, and send borderline scores to a “possible spam” folder rather than blocking them.
- Online: A/B test on spam reports and on appeals from people whose real messages were filtered.
- Monitoring: spammers adapt, so expect concept drift and retrain often. Blocked messages never get reported, which creates a feedback loop, so hold back a small random sample from filtering to keep measuring.
For the general framework, including scaling and storage, see our system design interview guide.
Behavioral questions for machine learning roles
- “Tell me about a model that didn’t work in production. What did you learn?”
- “When did you choose a simpler model over a more accurate one?”
- “How did you explain a model’s limitations to a non-technical stakeholder?”
- “Tell me about a time data quality changed your plan.”
Answer in STAR order (situation, task, action, result), and put a number on the result. Our STAR method guide has examples.
By role
- Machine learning engineers: expect coding, ML system design and production questions alongside the fundamentals. Our MLOps guide covers pipelines and monitoring.
- Data scientists: more statistics, experiments and SQL. See our data scientist interview questions.
- Research scientists: more math, deep learning depth and discussion of papers, including your own.
- AI and LLM engineers: see our AI engineer and LLM engineer interview questions. Interviewing at an AI lab? Read our OpenAI and Anthropic guides.
- Broader AI questions: our AI interview questions cover generative AI, agents, prompt injection and responsible AI.
How to prepare, step by step
- Explain each fundamental in two sentences, then give an example from your own work.
- Implement three things from scratch: logistic regression, k-means and the classification metrics.
- Rebuild one project’s pipeline with scikit-learn pipelines and a proper split, and look for leakage.
- Practice two ML system design prompts out loud, following the seven steps above.
- Prepare one project to go deep on: the data, the baseline, what failed and what you’d change.
- Write four behavioral stories about failure, trade-offs, communication and data quality.
Practice explaining your answers out loud
Frequently asked questions
What machine learning questions are asked in interviews?
How do I prepare for a machine learning interview?
What is ML system design?
What is data leakage in machine learning?
What is the difference between a machine learning engineer and a data scientist interview?
Do machine learning interviews include LeetCode-style coding?
Sources
- Google for Developers, Machine Learning Crash Course: Overfitting, L2 regularization, Imbalanced datasets, Accuracy, recall, precision, ROC and AUC and Normalization. Read on 11 November 2026.
- Google for Developers, Rules of Machine Learning, Random forests, Gradient boosted decision trees and the Machine learning glossary. Read on 11 November 2026.
- scikit-learn, Common pitfalls and recommended practices, Cross-validation, Linear models, Ensembles and Clustering. Read on 11 November 2026.
- Vaswani et al., Attention Is All You Need, 2017. He et al., Deep Residual Learning for Image Recognition, 2015. Ioffe and Szegedy, Batch Normalization, 2015. Ba, Kiros and Hinton, Layer Normalization, 2016. Srivastava et al., Dropout: A Simple Way to Prevent Neural Networks from Overfitting, Journal of Machine Learning Research, 2014.