Data science interview questions: statistics answers with real output
The statistics and analysis questions data science interviews return to, answered in plain words with Python you can run.
Data science interviews test statistics first: mean versus median, variance, distributions, hypothesis tests and p-values, confidence intervals, A/B test design and the difference between correlation and causation. Then come practical data questions (outliers, missing values, scaling) and modeling basics such as linear regression. Below are 20 questions; every example was run with Python and NumPy and shows its real output.
Basic data science interview questions
Basic1. When is the median better than the mean?
The mean uses every value, so one extreme value pulls it; the median is the middle value and barely moves. For skewed data such as incomes or house prices, report the median (or both).
Pythonimport numpy as np
pay = np.array([42, 45, 47, 50, 52, 55, 400]) # thousands
print('mean ', round(pay.mean(), 1))
print('median', np.median(pay))Output (Python 3.12.10 · NumPy 2.5.2)mean 98.7 median 50.0
Basic2. What is the difference between variance and standard deviation, and between sample and population versions?
Variance is the mean squared distance from the mean; standard deviation is its square root, in the data's own units. The sample version divides by n - 1 instead of n (ddof=1 in NumPy) to correct for estimating the mean from the same data.
Pythonimport numpy as np
x = np.array([4, 8, 6, 5, 3, 7])
print('population var', round(x.var(), 3), 'sd', round(x.std(), 3))
print('sample var ', round(x.var(ddof=1), 3), 'sd', round(x.std(ddof=1), 3))Output (Python 3.12.10 · NumPy 2.5.2)population var 2.917 sd 1.708 sample var 3.5 sd 1.871
Basic3. What does a p-value mean?
Assuming the null hypothesis is true, the p-value is the probability of seeing a result at least as extreme as the one observed. A small p-value means the data would be surprising under the null. It is not the probability that the null is true, and it says nothing about how large or important the effect is.
Basic4. What are Type I and Type II errors?
A Type I error is a false positive: rejecting a null hypothesis that is true (its rate is the significance level, alpha). A Type II error is a false negative: missing a real effect (its rate is beta; power is 1 - beta). Lowering one usually raises the other unless you collect more data.
Basic5. What is the difference between correlation and causation?
Correlation measures how two variables move together; causation means changing one changes the other. Two variables can correlate because of a shared cause, chance or reverse causation. Randomized experiments are the standard way to show causation.
Pythonimport numpy as np
rng = np.random.default_rng(0)
temp = rng.normal(25, 5, 200) # hidden common cause
ice_cream = 3 * temp + rng.normal(0, 5, 200)
sunburn = 2 * temp + rng.normal(0, 5, 200)
print('corr(ice cream, sunburn) =', round(np.corrcoef(ice_cream, sunburn)[0, 1], 2))Output (Python 3.12.10 · NumPy 2.5.2)corr(ice cream, sunburn) = 0.85
Basic6. How do you handle missing values?
First ask why they are missing: completely at random, related to other recorded variables, or related to the missing value itself. Options include dropping rows (if few and random), imputing with the median or a model, or adding an indicator column so the model can use missingness as information. Always impute using training data only.
Basic7. How do you detect outliers?
A common rule flags values more than 1.5 interquartile ranges below the first quartile or above the third. Z-scores work for roughly normal data. Before removing an outlier, check whether it is an error or a real, important case.
Pythonimport numpy as np
x = np.array([12, 13, 13, 14, 15, 15, 16, 17, 18, 45])
q1, q3 = np.percentile(x, [25, 75])
iqr = q3 - q1
low, high = q1 - 1.5 * iqr, q3 + 1.5 * iqr
print('bounds', low, high)
print('outliers', x[(x < low) | (x > high)])Output (Python 3.12.10 · NumPy 2.5.2)bounds 8.0 22.0 outliers [45]
Intermediate data science interview questions
Intermediate8. How does a permutation test work?
Shuffle the group labels many times and recompute the difference each time. The share of shuffled differences at least as large as the observed one is the p-value. It makes few assumptions about the data's distribution.
Pythonimport numpy as np
rng = np.random.default_rng(0)
a = np.array([12.1, 11.8, 13.0, 12.6, 12.9, 13.4, 12.2, 12.8]) # minutes, old checkout
b = np.array([11.2, 11.9, 11.5, 12.0, 11.1, 11.7, 12.3, 11.4]) # new checkout
obs = a.mean() - b.mean()
pooled = np.concatenate([a, b])
diffs = []
for _ in range(10_000):
rng.shuffle(pooled)
diffs.append(pooled[:8].mean() - pooled[8:].mean())
p = np.mean(np.abs(diffs) >= abs(obs))
print('observed difference', round(obs, 3))
print('two-sided p-value ', round(p, 4))Output (Python 3.12.10 · NumPy 2.5.2)observed difference 0.963 two-sided p-value 0.0018
Intermediate9. How do you build a confidence interval with the bootstrap?
Resample the data with replacement many times, compute the statistic each time, and take percentiles of those results (for example the 2.5th and 97.5th for a 95% interval). It works for medians and other statistics without a simple formula.
Pythonimport numpy as np
rng = np.random.default_rng(0)
times = rng.exponential(scale=8, size=60) # wait times in minutes
meds = [np.median(rng.choice(times, size=times.size, replace=True)) for _ in range(5000)]
lo, hi = np.percentile(meds, [2.5, 97.5])
print('sample median', round(np.median(times), 2))
print('95% bootstrap CI', round(lo, 2), 'to', round(hi, 2))Output (Python 3.12.10 · NumPy 2.5.2)sample median 6.08 95% bootstrap CI 4.31 to 8.2
Intermediate10. What does the central limit theorem say?
The distribution of a sample mean approaches a normal distribution as the sample size grows, whatever the shape of the original data (given finite variance), with standard deviation sigma divided by the square root of n. It is why many tests and intervals for means work.
Pythonimport numpy as np
rng = np.random.default_rng(0)
for n in (2, 10, 50):
means = rng.uniform(0, 1, size=(20_000, n)).mean(axis=1)
print(f'n={n:>2} sd of means={means.std():.4f} theory={np.sqrt(1/12)/np.sqrt(n):.4f}')Output (Python 3.12.10 · NumPy 2.5.2)n= 2 sd of means=0.2029 theory=0.2041 n=10 sd of means=0.0918 theory=0.0913 n=50 sd of means=0.0404 theory=0.0408
Intermediate11. How would you design an A/B test?
Pick one primary metric and a guardrail metric, state the hypothesis, decide the minimum effect worth detecting and compute the sample size from it, randomize at the right unit (usually the user), run for full business cycles, and avoid stopping early when the result first looks significant. Check that the groups are balanced before reading the result.
Intermediate12. What is the difference between normalization and standardization?
Min-max normalization rescales values to the range 0 to 1. Standardization (z-scores) subtracts the mean and divides by the standard deviation, giving mean 0 and standard deviation 1. Distance-based and gradient-based models need one of them; tree models do not.
Pythonimport numpy as np
x = np.array([20., 35., 50., 65., 80.])
print('min-max', np.round((x - x.min()) / (x.max() - x.min()), 2))
z = (x - x.mean()) / x.std()
print('z-score', np.round(z, 2), 'mean', round(z.mean(), 2), 'sd', round(z.std(), 2))Output (Python 3.12.10 · NumPy 2.5.2)min-max [0. 0.25 0.5 0.75 1. ] z-score [-1.41 -0.71 0. 0.71 1.41] mean 0.0 sd 1.0
Intermediate13. How do you fit and judge a linear regression?
Least squares chooses the coefficients that minimize the squared errors. R-squared is the share of variance in the target the model explains. Check the residuals for patterns, and judge the model on held-out data, not only on the data it was fitted to.
Pythonimport numpy as np
rng = np.random.default_rng(0)
x = rng.uniform(0, 10, 50)
y = 3.0 + 2.0 * x + rng.normal(0, 1.5, 50)
X = np.column_stack([np.ones_like(x), x])
coef, *_ = np.linalg.lstsq(X, y, rcond=None)
pred = X @ coef
r2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()
print('intercept', round(coef[0], 2), 'slope', round(coef[1], 2))
print('R^2', round(r2, 3))Output (Python 3.12.10 · NumPy 2.5.2)intercept 2.64 slope 2.08 R^2 0.943
Intermediate14. How does Bayes' theorem change a test result's meaning?
Bayes' theorem combines the prior (how common something is) with the test's accuracy. For a rare condition, even an accurate test gives many false positives, so a positive result can still mean a low chance of having the condition.
Pythonprior = 0.01 # 1% have the condition
sens = 0.95 # P(positive | condition)
spec = 0.90 # P(negative | no condition)
p_pos = sens * prior + (1 - spec) * (1 - prior)
posterior = sens * prior / p_pos
print(f'P(condition | positive) = {posterior:.3f}')Output (Python 3.12.10 · NumPy 2.5.2)P(condition | positive) = 0.088
Intermediate15. What is Simpson's paradox?
A trend that appears in every group can reverse when the groups are combined, because the groups are of different sizes and have different base rates. The fix is to look at the data at the level where the decision is made and think about which variable confounds the comparison.
Python# successes / attempts for two treatments in two patient groups
A = {'mild': (81, 87), 'severe': (192, 263)}
B = {'mild': (234, 270), 'severe': (55, 80)}
for g in ('mild', 'severe'):
print(g, 'A', round(A[g][0] / A[g][1], 3), 'B', round(B[g][0] / B[g][1], 3))
tot = lambda d: sum(s for s, n in d.values()) / sum(n for s, n in d.values())
print('combined A', round(tot(A), 3), 'B', round(tot(B), 3))Output (Python 3.12.10 · NumPy 2.5.2)mild A 0.931 B 0.867 severe A 0.73 B 0.688 combined A 0.78 B 0.826
Intermediate16. What kinds of sampling bias should you look for?
Selection bias (the sample is not representative, such as surveying only current customers), survivorship bias (only the successes remain visible), non-response bias (people who answer differ from those who do not) and measurement bias (the instrument or question skews answers).
Advanced data science interview questions
Advanced17. How do you choose the sample size for an A/B test?
It depends on the baseline rate, the smallest lift worth detecting, the significance level and the power. Smaller effects need many more users: halving the detectable effect roughly quadruples the sample size.
Pythonimport math
def n_per_group(p1, p2, z_alpha=1.96, z_beta=0.8416):
pbar = (p1 + p2) / 2
num = (z_alpha * math.sqrt(2 * pbar * (1 - pbar)) + z_beta * math.sqrt(p1 * (1 - p1) + p2 * (1 - p2))) ** 2
return math.ceil(num / (p2 - p1) ** 2)
for lift in (0.02, 0.01, 0.005):
print(f'baseline 10%, detect +{lift:.1%}: {n_per_group(0.10, 0.10 + lift):,} users per group')Output (Python 3.12.10 · NumPy 2.5.2)baseline 10%, detect +2.0%: 3,841 users per group baseline 10%, detect +1.0%: 14,751 users per group baseline 10%, detect +0.5%: 57,764 users per group
Advanced18. Why are multiple comparisons a problem, and how do you correct for them?
Each test at alpha 0.05 has a 5% false positive chance, so testing many metrics or segments makes at least one false positive likely. Corrections include Bonferroni (divide alpha by the number of tests) and controlling the false discovery rate (Benjamini-Hochberg). Pre-registering one primary metric avoids much of the problem.
Pythonfor k in (1, 5, 20):
print(f'{k:>2} independent tests: P(at least one false positive) = {1 - 0.95 ** k:.2f}')Output (Python 3.12.10 · NumPy 2.5.2)1 independent tests: P(at least one false positive) = 0.05 5 independent tests: P(at least one false positive) = 0.23 20 independent tests: P(at least one false positive) = 0.64
Advanced19. What is the difference between a model's statistical significance and its practical impact?
With enough data, tiny effects become statistically significant. Practical significance asks whether the effect is large enough to matter for the business, given its cost. Report effect sizes with confidence intervals, not only p-values.
Advanced20. How would you explain a data science project in an interview?
State the business question, the data and its problems, the methods you tried and why, how you validated the result, what decision it changed and what you would do differently. Interviewers look for judgment about trade-offs, not only technique.
How to practice with this page
- Explain each concept to a non-technical listener in two sentences before writing any code.
- Re-run each example with a different seed and say what changed and why.
- Practice the SQL round too: data science loops often include one.
- Prepare one project story: question, data, method, result and what you would do next.
Related interview prep
Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.
Questions people ask
What statistics should I know for a data science interview?
Do data science interviews include coding?
How do I practice data science interview questions?
What is the difference between data science and machine learning interviews?
Do I need to know R for a data science interview?
How this page is built
TryHired wrote these questions and answers. Every Python block on this page was executed with Python 3.12.10 · NumPy 2.5.2 when the page was built, and the output shown is the real output; the build stops if any example fails. The question list is general practice: it does not predict what a particular employer will ask.
- Interviewers ask different questions for different roles and levels.
- Answers are short explanations, not complete references.
- Examples use small synthetic data with fixed seeds; real data needs checking for quality first.
- NumPy documentation, statistics: https://numpy.org/doc/stable/reference/routines.statistics.html
- NumPy documentation, random generator: https://numpy.org/doc/stable/reference/random/generator.html
- NIST/SEMATECH e-Handbook of Statistical Methods: https://www.itl.nist.gov/div898/handbook/
- OpenIntro Statistics (free textbook): https://www.openintro.org/book/os/