Skip to content

Data Scientist Interview Questions & Answers

40 questions for Data Scientist interviews — 6 easy, 29 medium, 5 hard.

About the Data Scientist role

Data Scientists frame business questions as ML problems, explore data, engineer features and build predictive models for churn, credit risk, demand or marketing. They choose the right metrics, explain results with SHAP and charts, and translate model outputs into decisions for business teams. Strong statistics, pandas, scikit-learn and communication skills matter more than deep infrastructure knowledge in this role. Good SQL is expected too.

Problem framing Feature engineering Statistical modelling Model evaluation Stakeholder communication
Solved for this roleStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
3 questions free Unlock the rest in seconds
01

Train LightGBM with early stopping.

Save to ▾
Show answer
import lightgbm as lgb m = lgb.LGBMClassifier(n_estimators=5000, learning_rate=0.05, num_leaves=31, subsample=0.8, subsample_freq=1, colsample_bytree=0.8) m.fit(X_train, y_train, eval_set=[(X_val, y_val)], eval_metric='auc', callbacks=[lgb.early_stopping(100)]) print(m.best_iteration_) The large n_estimators is only an upper limit; early stopping picks the real number.
02

What is the bias-variance trade-off?

Save to ▾
Show answer
Bias is error from overly simple assumptions, which causes underfitting. Variance is error from sensitivity to the particular training sample, which causes overfitting. Increasing model complexity usually lowers bias but raises variance. The goal is the complexity that minimises total test error. For example, a linear model on curved data has high bias, while a very deep unpruned tree has high variance.
03

Compare grid search, random search and Bayesian optimisation.

Save to ▾
Show answer
Grid search tries every combination of listed values; it is thorough but expensive and wastes trials on unimportant parameters. Random search samples combinations and usually finds good settings faster in high-dimensional spaces. Bayesian optimisation, as in Optuna or Hyperopt, builds a model of past trials to pick promising settings next, using fewer trials. Successive halving methods add early pruning of weak trials.
04

Grid search with 5 hyperparameters is taking two days. How do you speed it up?

Save to ▾
Show answer
Switch to random search or Optuna with pruning, which find good settings with far fewer trials. Narrow ranges using a quick coarse search, tune the most important parameters first, use early stopping for boosting, run trials in parallel with n_jobs, and tune on a stratified sample of the data before a final refit on the full set. HalvingRandomSearchCV is another quick option.
05

What is the ROC curve and AUC? When is PR-AUC better?

Save to ▾
Show answer
The ROC curve plots true positive rate against false positive rate at every threshold, and AUC is the probability that a random positive is ranked above a random negative. It is threshold-independent. On heavily imbalanced data, like 0.5 percent fraud, ROC-AUC can look high even when precision is poor, so the precision-recall curve and PR-AUC give a more honest picture.
06

What is the log loss metric and why is it useful?

Save to ▾
Show answer
Log loss, or cross-entropy, is the negative average log of the probability assigned to the true class. It heavily penalises confident wrong predictions, such as predicting 0.99 for an event that does not happen. It evaluates probability quality, not just ranking, so it suits problems where probabilities drive decisions. Lower is better, and a constant base-rate prediction is the baseline to beat.
07

Check calibration with a reliability curve and Brier score.

Save to ▾
Show answer
from sklearn.calibration import CalibrationDisplay from sklearn.metrics import brier_score_loss proba = clf.predict_proba(X_test)[:, 1] print('Brier', brier_score_loss(y_test, proba)) CalibrationDisplay.from_predictions(y_test, proba, n_bins=10) plt.show() Points on the diagonal mean predicted probabilities match observed frequencies.
08

What are learning curves and validation curves?

Save to ▾
Show answer
A learning curve plots training and validation scores against training set size; if both converge at a low score the model underfits, and if a gap remains, more data may help. A validation curve plots scores against one hyperparameter, such as max_depth, showing where overfitting starts. Both help decide whether to collect data, add features or change complexity.
09

Tell me about a time you had to explain a model's error to a business team.

Save to ▾
Show answer
Situation: a sales forecast missed by 18 percent in one month. Task: explain why to the category team. Action: I broke the error down by region and found most came from a sudden promotion not in our data. I showed a simple chart and proposed adding a promotion calendar feed. Result: the team shared promotion plans in advance, and the next quarter's error fell below 8 percent.
10

What is regularisation in general and why does it reduce overfitting?

Save to ▾
Show answer
Regularisation adds a constraint or penalty that discourages overly complex models, such as large weights in linear models, deep trees or too many boosting rounds. It trades a little extra bias for a larger drop in variance, so test error falls. Examples include L1 and L2 penalties, dropout in neural networks, early stopping, pruning and limiting tree depth.
11

What are overfitting and underfitting, and how do you detect them?

Save to ▾
Show answer
Overfitting is when a model memorises training noise and performs much worse on unseen data. Underfitting is when the model is too simple to capture the pattern, so both training and validation scores are poor. Detect them by comparing training and validation metrics or plotting learning curves. A large gap means overfitting; two low, close scores mean underfitting.
12

How do you approach a time series forecasting problem differently from normal regression?

Save to ▾
Show answer
Time series data is ordered and autocorrelated, so random splits leak future information. I use time-based splits or TimeSeriesSplit, create lag and rolling-window features from past values only, and handle trend and seasonality. Baselines like last value or seasonal naive come first. Models range from ARIMA and Prophet to gradient boosting on lag features.
13

What is the kernel trick?

Save to ▾
Show answer
The kernel trick computes dot products of data in a high-dimensional feature space without explicitly transforming the data, using a kernel function such as RBF, exp(-gamma times squared distance). This lets linear algorithms like SVM learn non-linear boundaries efficiently. In RBF SVMs, larger gamma makes each point's influence more local, which can lead to overfitting.
14

What is the difference between parameters and hyperparameters?

Save to ▾
Show answer
Parameters are learned from data during training, such as the weights of a linear regression or split thresholds of a tree. Hyperparameters are set before training and control the learning process, such as learning rate, max_depth, number of trees or regularisation strength C. Hyperparameters are tuned with validation data using grid search, random search or Bayesian optimisation.
15

Why do you want to work as a machine learning engineer?

Save to ▾
Show answer
I enjoy turning data into decisions that people actually use. During my projects I liked the full cycle: framing the problem, cleaning messy data, comparing models and explaining results. ML engineering lets me combine coding with statistics and see measurable business impact, such as reducing manual review time. I also want to keep growing into deployment and monitoring, which I am already practising with FastAPI and Docker.
16

Explain the k-nearest neighbours algorithm and its weaknesses.

Save to ▾
Show answer
k-NN predicts by finding the k closest training points and taking a majority vote for classification or the average for regression. It has no training phase but is slow at prediction on large data, needs feature scaling, suffers from the curse of dimensionality and is sensitive to irrelevant features. Small k overfits, large k underfits; choose k with cross-validation.
17

Explain the bias in AUC when classes are extremely imbalanced, with a numeric intuition.

Save to ▾
Show answer
With 100 fraud and 100,000 genuine cases, a false positive rate of 1 percent looks tiny on the ROC curve, but it means 1,000 false alerts versus at most 100 true ones, so precision is below 10 percent. ROC-AUC can be 0.97 while the model is impractical. Precision-recall curves expose this because precision directly depends on the count of false positives.
18

An A/B test of a new recommendation model shows no significant uplift despite better offline metrics. What next?

Save to ▾
Show answer
I would check the test first: enough sample size and duration, correct randomisation, and no bugs in serving such as stale features. Then investigate whether offline metrics really reflect user value, for example optimising clicks rather than purchases, or popularity bias. Segment-level analysis may show gains in some groups. I would revise the offline metric to better match the online goal.
19

Your manager asks for a single number showing the model's business value. What do you give?

Save to ▾
Show answer
I would convert model outcomes into money or time using a cost matrix agreed with the business, for example savings from caught fraud minus the cost of reviewing false alerts. I would compare this against the current process or a rule-based baseline on holdout data and show a range rather than one point. A short note on assumptions keeps the number honest.
20

When would you use Huber or quantile regression instead of OLS?

Save to ▾
Show answer
Huber regression uses squared loss for small errors and absolute loss for large ones, so it resists outliers while staying smooth. Quantile regression predicts a chosen percentile, such as the 90th percentile of delivery time, which is useful for setting safe promises or prediction intervals. Gradient boosting libraries support both losses for non-linear versions.
21

Tell me about a time you took a model from notebook to production.

Save to ▾
Show answer
Situation: our demand model ran only in a notebook on my laptop. Task: make it run daily for 300 stores. Action: I refactored it into modules with a scikit-learn pipeline, added tests and input checks, containerised it with Docker and scheduled it with Airflow writing forecasts to the warehouse. Result: forecasts became available by 6 a.m. daily without manual work, and failures triggered alerts instead of silent gaps.
22

How do you choose a classification threshold that maximises F1?

Save to ▾
Show answer
from sklearn.metrics import precision_recall_curve import numpy as np proba = clf.predict_proba(X_val)[:, 1] p, r, t = precision_recall_curve(y_val, proba) f1 = 2 * p * r / (p + r + 1e-9) best = t[np.argmax(f1[:-1])] print(best) Choose it on validation data, not the test set. scikit-learn 1.5+ also offers TunedThresholdClassifierCV.
23

What is heteroscedasticity and why does it matter?

Save to ▾
Show answer
Heteroscedasticity means the variance of residuals changes with the level of the prediction, such as errors growing for expensive houses. Predictions remain unbiased, but standard errors and p-values become unreliable. Detect it with a residuals versus fitted plot or the Breusch-Pagan test. Fixes include log-transforming the target, weighted least squares, or robust standard errors.
24

How does logistic regression work?

Save to ▾
Show answer
Logistic regression computes a weighted sum of features and passes it through the sigmoid function, 1 / (1 + e^-z), to get a probability between 0 and 1. It is trained by minimising log loss. Coefficients represent change in log-odds per unit of a feature, and exp(coefficient) gives the odds ratio. A threshold, 0.5 by default, converts probabilities into class labels.
25

How do you plot an ROC curve and get AUC in scikit-learn?

Save to ▾
Show answer
from sklearn.metrics import roc_auc_score, RocCurveDisplay import matplotlib.pyplot as plt proba = clf.predict_proba(X_test)[:, 1] print('AUC', roc_auc_score(y_test, proba)) RocCurveDisplay.from_predictions(y_test, proba) plt.show() Pass probabilities or decision scores, not hard labels, otherwise the curve has only one point.
26

What is the difference between Ridge, Lasso and Elastic Net regression?

Save to ▾
Show answer
All add a penalty on coefficient size to reduce overfitting. Ridge uses an L2 penalty (sum of squares), shrinking coefficients toward zero but rarely to zero, and handles multicollinearity well. Lasso uses L1 (sum of absolute values) and can set coefficients exactly to zero, performing feature selection. Elastic Net mixes both, which is useful when there are groups of correlated features.
27

How do one-vs-rest and multinomial approaches differ for multiclass classification?

Save to ▾
Show answer
One-vs-rest trains one binary classifier per class against all others and picks the highest score; it is simple but probabilities may not sum to one. Multinomial (softmax) logistic regression models all classes jointly with a single loss, giving consistent probabilities. For metrics, use macro averaging to treat classes equally or weighted averaging to account for class frequency.
28

A demand forecast is consistently under-predicting during festivals. How would you fix it?

Save to ▾
Show answer
The model lacks festival information. I would add features for festival dates such as Diwali or regional holidays, days-to-festival, and past festival uplift for the same item. If the business cost of stock-outs is higher than over-stock, I would use a quantile loss for a higher percentile. Then validate specifically on past festival periods, not just the average error.
29

How do you tune the alpha of Ridge regression using cross-validation?

Save to ▾
Show answer
RidgeCV tests many alphas efficiently; scale features first. from sklearn.linear_model import RidgeCV from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler import numpy as np m = make_pipeline(StandardScaler(), RidgeCV(alphas=np.logspace(-3, 3, 30))) m.fit(X_train, y_train) print(m[-1].alpha_) LassoCV and ElasticNetCV work the same way.
30

Your house price model's residuals grow larger for expensive houses. What do you do?

Save to ▾
Show answer
That is heteroscedasticity, typical for price data that is right-skewed. I would model log(price) instead of price, which turns absolute errors into roughly percentage errors and stabilises variance. Then I would convert predictions back with exp and check residual plots again. Evaluating with RMSLE or MAPE also fits better when relative error matters more than absolute error.
31

What is the difference between batch, stochastic and mini-batch gradient descent?

Save to ▾
Show answer
Batch gradient descent uses the full dataset for each update, giving stable but slow and memory-heavy steps. Stochastic gradient descent updates after every single example, which is fast and noisy and can escape shallow minima. Mini-batch uses small groups such as 32 to 512 rows, balancing stability with speed and allowing vectorised computation. Mini-batch is the default in practice.
32

What is the difference between offline evaluation and online A/B testing of a model?

Save to ▾
Show answer
Offline evaluation measures metrics like AUC on historical holdout data; it is fast and cheap but cannot capture user behaviour changes or feedback loops. Online A/B testing exposes a share of real traffic to the new model and measures business outcomes like conversion or loss rate. Offline gains do not always translate online, so important models are validated with A/B tests or shadow deployments.
33

How does a support vector machine work?

Save to ▾
Show answer
An SVM finds the hyperplane that separates classes with the maximum margin, and the points on the margin are the support vectors. The soft-margin version uses C to trade off margin width against misclassification. Kernels like RBF or polynomial let SVMs learn non-linear boundaries by implicitly mapping data to higher dimensions. SVMs need scaled features and become slow beyond roughly a hundred thousand rows.
34

Plot a learning curve in scikit-learn.

Save to ▾
Show answer
from sklearn.model_selection import LearningCurveDisplay import numpy as np LearningCurveDisplay.from_estimator(model, X, y, cv=5, train_sizes=np.linspace(0.1, 1.0, 6), scoring='roc_auc', n_jobs=-1) plt.show() A persistent gap between curves suggests more data or regularisation; two low curves suggest a richer model or better features.
35

What is the softmax function?

Save to ▾
Show answer
Softmax turns a vector of raw scores into probabilities that sum to one: p_i = exp(z_i) / sum of exp(z_j). It is used in multinomial logistic regression and the output layer of neural networks for multiclass problems. Larger scores get exponentially larger shares. In practice the maximum score is subtracted before exponentiation to avoid numerical overflow.
36

What is a model registry and why is it useful?

Save to ▾
Show answer
A model registry is a central store of model versions with metadata: training data version, parameters, metrics, owner and stage such as staging or production. It makes promotions and rollbacks controlled and auditable, and lets serving systems load a model by name and version. MLflow Model Registry, SageMaker Model Registry and Vertex AI Model Registry are common examples.
37

Tell me about a time you balanced model accuracy against a business constraint.

Save to ▾
Show answer
Situation: our lead-scoring model had the best AUC with a large ensemble, but the CRM needed scores within 50 ms. Task: meet latency without losing much quality. Action: I compared a smaller LightGBM model with fewer features and measured both AUC and latency. Result: we lost 0.01 AUC but met the 50 ms limit, and sales teams adopted it because scores appeared instantly.
38

You are asked to predict customer churn. How would you frame the ML problem from scratch?

Save to ▾
Show answer
First define churn precisely, for example no purchase in 60 days, and the prediction window. It becomes binary classification. Build features from data available before the cut-off date only, choose a time-based split, and pick metrics like recall at a fixed precision or lift in the top decile. Start with logistic regression as a baseline, then try boosting, and agree on how retention teams will use the scores.
39

What is the no free lunch theorem and what does it mean in practice?

Save to ▾
Show answer
It states that no single algorithm is best for every problem when averaged over all possible problems. In practice it means you should try several model families, start with a simple baseline, and choose based on validation results for your data. For tabular data gradient boosting often wins, but a logistic regression may be preferred if interpretability matters more.
40

Two models have RMSE 120 and 125, but the second has much lower MAE. Which do you choose?

Save to ▾
Show answer
It depends on error cost. The first model makes fewer big errors, while the second is better on typical cases but has some large misses. If large errors are expensive, such as stock-outs of costly items, choose the first. If typical accuracy matters more, choose the second. I would also check error distributions by segment and discuss with stakeholders before deciding.

Frequently asked questions

What does a Data Scientist do?

Data Scientists frame business questions as ML problems, explore data, engineer features and build predictive models for churn, credit risk, demand or marketing. They choose the right metrics, explain results with SHAP and charts, and translate model outputs into decisions for business teams. Strong statistics, pandas, scikit-learn and communication skills matter more than deep infrastructure knowledge in this role. Good SQL is expected too.

Which skills are tested in a Data Scientist interview?

Expect questions on Problem framing, Feature engineering, Statistical modelling, Model evaluation, Stakeholder communication. Most rounds also ask you to explain a project and solve one practical problem live.

How do I prepare for a Data Scientist interview?

Revise ML Fundamentals, Classification Models, Regression Models, Model Evaluation and Tuning first using the topic sheets, practise the questions on this page aloud, then do one full mock interview to practise timing.