Data Scientist Interview Questions and Answers
Last updated 2026-11-19
Data scientist interviews mix machine learning theory, statistics, coding and an open-ended modelling problem. A typical loop has a coding screen (Python and SQL), a statistics and ML round, a case such as "predict churn" and a conversation about a past project. These questions cover the core ones with worked answers.
Where a question has numbers, work them by hand once, because interviewers often change the numbers. The process side is covered in how to crack the data science interview; for the algorithms in more detail see machine learning interview questions.
| Typical rounds | Coding screen, ML and statistics, case study, project discussion |
|---|---|
| Core skills | Python, SQL, statistics, machine learning |
| Questions here | 13 worked questions |
What a modelling case looks for
A good answer follows a fixed path: define the target and the cost of each error, choose a metric, build a simple baseline, split data in a way that matches deployment, engineer features, compare models, check errors by segment and plan monitoring. Candidates lose marks by jumping to a complex model before stating a baseline or a metric.
Topics to revise
- Bias-variance trade-off, regularisation and cross-validation.
- Classification metrics: precision, recall, F1, ROC AUC and PR AUC.
- Data leakage, class imbalance and time-based splits.
- Hypothesis testing and A/B testing basics.
- SQL window functions and pandas joins.
Data Scientist Interview Questions and Answers: questions with worked answers
1 Explain the bias-variance trade-off.
easyExpected test error splits into bias squared, variance and irreducible noise. Bias is error from a model that is too simple to capture the pattern, so it underfits. Variance is error from a model so flexible that it changes a lot with the training sample, so it overfits. A depth-1 tree has high bias and low variance; an unpruned tree has low bias and high variance. You reduce variance with more data, regularisation, bagging or simpler models, and bias with richer features or a more flexible model.
2 Compare L1 and L2 regularisation.
mediumL1 (lasso) adds lambda times the sum of absolute weights; L2 (ridge) adds lambda times the sum of squared weights. L1 produces exact zeros because its penalty has a corner at zero, so it performs feature selection. L2 shrinks all weights smoothly and handles correlated features by spreading weight among them. Features must be scaled first, otherwise the penalty treats features unequally. Elastic net mixes both.
3 Compute precision, recall and F1 from a confusion matrix of TP=40, FP=10, FN=20, TN=930.
easyPrecision = TP / (TP + FP) = 40 / 50 = 0.80. Recall = TP / (TP + FN) = 40 / 60 = 0.667. F1 is the harmonic mean: 2 x 0.8 x 0.667 / (0.8 + 0.667) = 0.727. Accuracy is (40 + 930) / 1000 = 97 percent, which looks excellent but only because 94 percent of cases are negative; always quote precision and recall when classes are imbalanced.
pythontp, fp, fn, tn = 40, 10, 20, 930 precision = tp / (tp + fp) # 0.8 recall = tp / (tp + fn) # 0.6667 f1 = 2 * precision * recall / (precision + recall) # 0.72734 What is data leakage? Give two examples and how to prevent it.
mediumLeakage is when information unavailable at prediction time enters training, giving optimistic validation scores that collapse in production. Example one: fitting a scaler or imputer on the full dataset before splitting, so test statistics leak into training. Example two: a feature such as "refund issued" when predicting churn, which only exists after the event. Prevent it by splitting first, wrapping preprocessing inside a Pipeline, using time-based splits for temporal data, and auditing feature definitions against the prediction moment.
pythonfrom sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression from sklearn.model_selection import cross_val_score pipe = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) scores = cross_val_score(pipe, X, y, cv=5, scoring='roc_auc')5 How would you handle a dataset with 1 percent positives?
mediumFirst, choose metrics that do not hide the problem: PR AUC, recall at a fixed precision, not accuracy. Keep the validation set at the natural class ratio. For training, try class weights, which is usually the simplest, then threshold tuning on predicted probabilities, then resampling such as undersampling the majority class. Apply SMOTE or any resampling only inside the training folds. Finally, choose the threshold from the business cost of a false negative versus a false positive.
6 Explain k-fold cross-validation and when to avoid plain k-fold.
mediumSplit data into k parts, train on k-1 and validate on the remaining one, rotate k times and average the scores, giving a lower-variance estimate than a single split. Avoid plain k-fold when rows are not independent: use stratified k-fold for imbalanced classes, group k-fold when the same customer appears in several rows, and time-series split when order matters so that you never train on the future.
7 Difference between bagging and boosting?
mediumBagging trains many models independently on bootstrap samples and averages them, which mainly reduces variance; random forest is the standard example. Boosting trains models in sequence, each one focusing on the errors of the previous ensemble, which mainly reduces bias; gradient boosting, XGBoost and LightGBM are examples. Boosting is usually more accurate on tabular data but is more sensitive to noisy labels and needs tuning of learning rate, depth and number of trees.
8 A model has 0.90 AUC on training and 0.72 on validation. What do you do?
mediumThe large gap signals overfitting. Check for leakage in the opposite direction too, but first reduce capacity: stronger regularisation, shallower trees, early stopping, fewer features. Get more data or augment if possible. Compare learning curves: if validation error is still falling with more data, collect more; if both curves have plateaued apart, the model is too flexible for the signal. Confirm the validation split matches how the model will be used.
9 Write SQL to get each user's latest order.
mediumRank each user's orders by date descending with ROW_NUMBER and keep rank 1. ROW_NUMBER breaks ties arbitrarily, so add a second sort key such as order_id to make it deterministic. A correlated subquery with MAX(order_date) is an alternative but returns several rows on ties.
sqlSELECT user_id, order_id, order_date FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY order_date DESC, order_id DESC) AS rn FROM orders ) t WHERE rn = 1;10 How do you interpret logistic regression coefficients?
mediumEach coefficient is the change in log-odds for a one-unit increase in the feature, holding others fixed. Exponentiate it for an odds ratio. A coefficient of 0.69 gives e^0.69 = 2, so the odds double per unit. Probability change is not constant, since the sigmoid is nonlinear. Scale features before comparing coefficient sizes.
11 State the null hypothesis and interpret a p-value of 0.03.
easyThe null hypothesis is the default of no effect or no difference. A p-value of 0.03 means that if the null were true, data at least as extreme as observed would occur about 3 percent of the time. It is not the probability that the null is true, and not the probability the result is a fluke. At a 5 percent significance level you reject the null, but you should also report the effect size and a confidence interval.
12 Explain how a random forest works and why feature scaling is not needed.
easyIt builds many decision trees, each on a bootstrap sample of rows and with a random subset of features at every split, then averages predictions (or takes a majority vote). The randomness decorrelates the trees, so averaging cuts variance. Splits compare a feature to a threshold, and any monotonic rescaling leaves the best split unchanged, so scaling has no effect on trees.
13 How would you deploy and monitor a model after training?
hardPackage preprocessing and the model together, version both, and serve through a batch job or an API depending on latency need. Log inputs and predictions. Monitor input drift (for example the population stability index on key features), prediction drift, and, when labels arrive, real performance by segment. Set alert thresholds and a retraining trigger, and keep the previous model for rollback. Start with a shadow or small-traffic release.
Frequently asked questions
Is DSA asked in data scientist interviews?
Usually light: arrays, strings, hash maps and sometimes easy-to-medium problems. Python and SQL fluency matters more than hard algorithms.
How much math do I need?
Linear algebra basics, probability, descriptive and inferential statistics and the calculus behind gradient descent. You should be able to derive simple things such as the mean squared error gradient.
What should my project discussion cover?
The business question, the data, your baseline, the metric, what failed, and what you would change. Be ready to defend each modelling choice.
Should I learn deep learning for a data science role?
For most tabular roles, gradient boosting and statistics matter more, but basic neural network knowledge is commonly expected. See the deep learning page for that.
Related guides
- Machine Learning Interview Questions and Answers
- Statistics for Data Science Interview Questions and Answers
- Probability for Data Science Interview Questions and Answers
- A/B Testing Interview Questions and Answers
- Deep Learning Interview Questions and Answers
- Data Analyst Interview Questions and Answers
- Pandas Interview Questions and Answers
More in Role-wise Interview Questions by Job and Tech Stack
- Deep Learning Interview Questions and Answers
- DevOps Interview Questions and Answers
- Django Interview Questions and Answers (Django 5)
- Docker Interview Questions and Answers
- Ethical Hacking Interview Questions and Answers
- ETL and Data Warehousing Interview Questions and Answers
- Excel Interview Questions and Answers
- Express.js Interview Questions and Answers (Express 5)
- FastAPI Interview Questions and Answers
- Flask Interview Questions and Answers
- Flutter Interview Questions and Answers (Flutter 3, Dart 3)
- Frontend Developer Interview Questions and Answers