Data science interviews cover a broad range: statistics, machine learning theory, Python coding, SQL, case studies, and system design. This guide covers the 50 questions most frequently asked in data science interviews at top companies in 2026, with concise answers you can actually use.
Statistics and Probability
1. What is the Central Limit Theorem? The CLT states that the sampling distribution of the mean approaches a normal distribution as sample size increases, regardless of the population’s distribution. Practically: it justifies using t-tests and z-tests on non-normal data when n > 30.
2. Explain p-value in plain English. The p-value is the probability of observing data at least as extreme as yours, assuming the null hypothesis is true. A p-value of 0.04 means there is a 4% chance of seeing this result if there is no real effect. It is not the probability that your hypothesis is true.
3. What is the difference between Type I and Type II errors? Type I (false positive): rejecting H₀ when it is actually true — saying an effect exists when it does not. Type II (false negative): failing to reject H₀ when it is false — missing a real effect. The significance level α controls Type I error rate. Statistical power (1-β) controls Type II error rate.
4. What is the difference between correlation and causation? Correlation measures the linear relationship between two variables. Causation means one variable directly causes changes in another. Correlation does not imply causation — both may be driven by a confounding variable, or the correlation may be coincidental. Establishing causation requires randomised controlled experiments or causal inference methods.
5. Explain confidence intervals. A 95% CI means: if we repeated the experiment 100 times and computed a CI each time, about 95 of those intervals would contain the true parameter. It is not “95% probability the parameter is in this interval” — that is a Bayesian credible interval.
Machine Learning Theory
6. What is the bias-variance tradeoff? Bias is error from wrong assumptions (underfitting). Variance is error from sensitivity to training data (overfitting). Total error = Bias² + Variance + Irreducible Noise. Increasing model complexity decreases bias but increases variance. The goal is to find the complexity that minimises total error on unseen data.
7. How does gradient descent work? Gradient descent minimises a loss function by iteratively moving in the direction of the negative gradient. At each step: θ = θ – α × ∇L(θ), where α is the learning rate. Stochastic GD uses one sample per update (noisy but fast). Mini-batch GD (most common) uses a small batch per update, balancing noise and efficiency.
8. What is regularisation and why use it? Regularisation adds a penalty term to the loss function to prevent overfitting. L1 (Lasso) penalises the sum of absolute weights — drives some to exactly zero, performing feature selection. L2 (Ridge) penalises the sum of squared weights — shrinks all weights toward zero without zeroing them. ElasticNet combines both.
9. Explain cross-validation. Cross-validation estimates how a model generalises to unseen data by splitting training data into k folds, training on k-1 folds, and evaluating on the remaining fold — repeated k times. The average validation score estimates generalisation performance. Use stratified K-fold for classification to preserve class ratios. Never include test data in cross-validation.
10. What is the difference between bagging and boosting? Bagging (Random Forest) trains multiple models in parallel on random subsets of data and averages their predictions. It reduces variance. Boosting (XGBoost, LightGBM) trains models sequentially, each correcting errors of the previous. It reduces bias. Bagging is less prone to overfitting; boosting typically achieves higher accuracy on tabular data.
Algorithms
11. How does a decision tree choose splits? Decision trees choose the feature and threshold that maximises information gain (for classification) or minimises MSE (for regression). Information gain = parent impurity minus weighted average child impurity. Gini impurity and entropy are the two common impurity measures for classification.
12. Explain how Random Forest works. Random Forest builds N decision trees, each trained on a bootstrap sample (random rows with replacement) of the training data. At each split, only a random subset of features (typically √n_features) is considered. Predictions are averaged (regression) or majority-voted (classification). The randomness reduces correlation between trees, reducing variance.
13. What is the kernel trick in SVM? The kernel trick maps data into a higher-dimensional space where it becomes linearly separable, without explicitly computing the transformed coordinates. The RBF kernel computes K(x, z) = exp(-γ||x-z||²), which implicitly computes infinite-dimensional dot products. This makes SVMs effective on non-linearly separable data without the computational cost of explicit feature expansion.
14. How does k-nearest neighbours work? KNN classifies a new point by finding the K training points closest to it (using Euclidean distance by default) and returning the majority class (or mean for regression). K is a hyperparameter. Small K = high variance, large K = high bias. KNN is non-parametric, requires no training, but is slow at inference on large datasets and sensitive to feature scale.
15. What is the difference between precision and recall? Precision = TP / (TP + FP) — of all predicted positives, how many are actually positive. Recall = TP / (TP + FN) — of all actual positives, how many did we detect. High precision minimises false positives (important in spam detection). High recall minimises false negatives (important in disease screening). F1 = harmonic mean of both.
Python and Coding
16. How do you handle class imbalance? Approaches: (1) Resample — oversample the minority class (SMOTE) or undersample the majority. (2) Class weights — set class_weight=’balanced’ in sklearn models. (3) Use the right metric — AUC-ROC, precision-recall AUC, or F1 instead of accuracy. (4) Threshold tuning — adjust the classification threshold based on your precision-recall tradeoff requirements.
17. Explain list comprehensions vs map/filter. List comprehensions are more Pythonic and readable for simple transformations: [x*2 for x in lst if x > 0]. map() applies a function to every element (returns an iterator), filter() selects elements by predicate. For complex logic use list comprehensions; for functional programming style use map/filter. Both are faster than explicit for loops for simple operations.
18. What is the difference between deep copy and shallow copy? A shallow copy creates a new object but references the same nested objects. A deep copy creates entirely independent copies of all nested objects. In Python: copy.copy() for shallow, copy.deepcopy() for deep. For pandas DataFrames: df.copy(deep=True) is a deep copy.
19. How do you profile Python code for performance bottlenecks? Use cProfile for function-level profiling: python -m cProfile -s cumulative script.py. Use line_profiler for line-level: @profile decorator + kernprof. Use memory_profiler for RAM usage. For pandas operations, df.info(memory_usage=’deep’) shows DataFrame memory. Vectorise operations over iterrows() — it is 10-100x faster.
20. What is a generator in Python and when would you use one? A generator is a function that yields values one at a time, rather than returning a full list. It is memory-efficient for large sequences because it generates values on demand. Use generators when processing large files line-by-line, streaming data pipelines, or when you only need to iterate through the sequence once.
SQL
21. What is the difference between WHERE and HAVING? WHERE filters rows before aggregation. HAVING filters groups after aggregation. You cannot use aggregate functions in WHERE. Example: SELECT dept, AVG(salary) FROM emp WHERE active=1 GROUP BY dept HAVING AVG(salary) > 50000.
22. Explain window functions. Window functions perform calculations across a set of rows related to the current row without collapsing the result set. Unlike GROUP BY, each row keeps its individual identity. Key functions: ROW_NUMBER(), RANK(), LAG(), LEAD(), SUM() OVER(), AVG() OVER(). Use them for running totals, rankings, and period-over-period comparisons.
23. What is the difference between INNER, LEFT, RIGHT, and FULL JOIN? INNER JOIN: only rows matching in both tables. LEFT JOIN: all rows from left table, NULLs for non-matching right rows. RIGHT JOIN: all rows from right table, NULLs for non-matching left rows. FULL JOIN: all rows from both tables, NULLs where no match. Most common: LEFT JOIN for including all records from the primary table.
24. How would you find duplicate rows in SQL? SELECT col1, col2, COUNT(*) as cnt FROM table GROUP BY col1, col2 HAVING COUNT(*) > 1. To see full duplicate rows: use a CTE with ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY id) and filter WHERE rn > 1.
25. What is query optimisation and how do you approach it? Start with EXPLAIN ANALYZE to see the query plan and identify expensive operations (sequential scans, hash joins on large tables). Add indexes on columns used in WHERE, JOIN, and ORDER BY. Avoid SELECT * — specify only needed columns. Push filters as early as possible. Materialise intermediate results for complex CTEs. Partition large tables by date.
System Design and Case Studies
26. How would you design a recommendation system? Start by defining the recommendation objective (CTR, revenue, retention). Collect user-item interactions. Use collaborative filtering (matrix factorisation) for “users like you also liked” recommendations, content-based filtering for item similarity, and a hybrid for cold-start users. Serve recommendations from pre-computed embeddings via approximate nearest neighbour search (Faiss). Evaluate offline (precision@k, NDCG) and online (A/B test CTR).
27. How would you detect anomalies in a time series? For statistical anomalies: Z-score or IQR thresholds on rolling windows. For contextual anomalies: Isolation Forest, LOF, or autoencoder reconstruction error. For seasonal data: decompose first (STL), then detect anomalies in residuals. In production, add streaming detection with ADTK or River library. Alert when consecutive anomalies occur, not on single spikes.
28. How would you measure the impact of a new feature launch? Ideal: run an A/B test — randomly split users, expose treatment to 50%, measure primary and guardrail metrics. Analyse with a t-test or Bayesian A/B framework. If A/B is not possible: difference-in-differences, synthetic control (compare to similar markets), or interrupted time series analysis. Define your primary metric and minimum detectable effect before launching.
29. A model performs well in training but poorly in production. What do you check? First: check for data leakage — features that implicitly include information from the future or from the target. Second: check for distribution shift — production data may differ from training data (different time period, user demographics, feature pipeline bugs). Third: check the evaluation setup — was the test set truly held out? Fourth: check for concept drift — the underlying relationship between features and target may have changed.
30. How do you handle a highly imbalanced dataset (1% positive class)? Never use accuracy as the metric — a model that predicts all negatives gets 99% accuracy. Use AUC-ROC, precision-recall AUC, or F1. Techniques: SMOTE oversampling, scale_pos_weight in XGBoost (set to neg/pos ratio), class_weight=’balanced’ in sklearn. Calibrate probability outputs if you need well-calibrated scores. Consider anomaly detection framing instead of binary classification.
Practical and Behavioural
31-50 (rapid-fire answers):
31. Difference between mean and median? Mean is sensitive to outliers; median is robust. Use median when data is skewed or has outliers.
32. What is multicollinearity and how do you detect it? High correlation between features, causing unstable coefficient estimates in linear models. Detect with Variance Inflation Factor (VIF > 10 is problematic).
33. What is PCA? Principal Component Analysis reduces dimensionality by finding orthogonal directions of maximum variance. Useful for preprocessing and visualisation.
34. Explain gradient vanishing problem. In deep networks, gradients shrink as they backpropagate through many layers, making early layers learn very slowly. Fixed by ReLU activations, batch normalisation, residual connections, and careful weight initialisation.
35. What is dropout? Regularisation technique that randomly sets a fraction of neurons to zero during training, preventing co-adaptation and reducing overfitting. Disabled at inference time.
36. What is batch normalisation? Normalises layer inputs to have zero mean and unit variance during training, accelerating training and reducing sensitivity to weight initialisation.
37. What is the ROC curve? Plots true positive rate vs false positive rate at various classification thresholds. AUC = area under the curve; 0.5 = random, 1.0 = perfect.
38. What is data leakage? When information from outside the training window is included in training features, causing artificially high training scores that collapse in production.
39. What is the difference between parametric and non-parametric models? Parametric models (linear regression, logistic regression, neural networks) have a fixed number of parameters. Non-parametric models (KNN, decision trees, GPs) grow with data.
40. What is transfer learning? Using a model pretrained on a large dataset (ImageNet, Wikipedia) and fine-tuning it on a smaller domain-specific dataset. Dramatically reduces data and compute requirements.
41. What is attention in transformers? Attention computes a weighted sum of value vectors, where weights come from the similarity between query and key vectors. Self-attention lets each token attend to all other tokens in the sequence.
42. Explain SMOTE. Synthetic Minority Over-sampling Technique creates synthetic samples in the minority class by interpolating between existing minority samples and their k nearest neighbours.
43. What is normalisation vs standardisation? Normalisation (Min-Max scaling) scales to [0,1]. Standardisation (Z-score) gives zero mean and unit variance. Use standardisation for most ML models; normalisation when you need bounded output.
44. What is a confusion matrix? A 2×2 table (for binary) showing TP, FP, FN, TN counts. Derives precision, recall, F1, specificity, and accuracy.
45. What is ensemble learning? Combining multiple models to improve prediction accuracy. Approaches: bagging (average independent models), boosting (sequential correction), stacking (meta-learner on base model predictions).
46. What is the curse of dimensionality? As dimensions increase, data becomes increasingly sparse, distances become less meaningful, and models need exponentially more data to generalise well.
47. What is the difference between supervised, unsupervised, and semi-supervised learning? Supervised: labelled data, predict output from input. Unsupervised: no labels, find structure (clustering, dimensionality reduction). Semi-supervised: some labels, leverages unlabelled data to improve.
48. What is a learning rate and how do you choose it? Controls the step size in gradient descent. Too high = overshooting, divergence. Too low = slow convergence. Use learning rate warmup + cosine annealing schedule for neural networks. For tree models, 0.01-0.1 with early stopping is standard.
49. What is A/B testing? A controlled experiment that randomly assigns users to control (A) or treatment (B) groups and measures whether the treatment causes a statistically significant difference in a primary metric.
50. How do you explain a model result to a non-technical stakeholder? Focus on business impact, not technical metrics. Translate AUC to “the model correctly identifies X% of churners before they leave, letting us intervene.” Use SHAP values to explain individual decisions in plain language. Lead with the recommendation, then support it with evidence. Acknowledge uncertainty.
Conclusion
The best interview preparation combines conceptual understanding with hands-on practice. For every concept listed here, write the code, run it, and explain it out loud as if teaching a colleague. Interviewers are not just testing what you know — they are testing how you think through problems under pressure. A clear, structured answer that acknowledges limitations is more impressive than a perfect rote answer delivered without understanding.



