---
title: Maths and statistics for ML interviews
url: https://gurkanozkan.ai/learn/topics/maths-statistics/
markdown: https://gurkanozkan.ai/learn/topics/maths-statistics.md
kind: topic
tracks:
  - Research
  - ML engineering
  - Applied LLM
json: https://gurkanozkan.ai/api/learn/topics/maths-statistics.json
---

# Maths and statistics for ML interviews

This guide covers the maths that interviewers expect you to produce on a whiteboard without notes: Bayes' rule and base rates, estimation (MLE, MAP, bias), uncertainty (standard error, confidence intervals, hypothesis tests, power), information theory (entropy, cross-entropy, KL), linear algebra (eigenvectors, SVD, rank) and calculus for learning (gradients, Jacobians, autodiff). Research roles test derivations; MLE and applied LLM roles test whether you can decide if an A/B result or an eval gain is real and how many samples you need. Since 2025 the same tools are applied to LLM and agent evaluation: small benchmarks where normal-approximation intervals fail, repeated trials per task, pass@k versus pass^k, and the linear algebra behind newer optimisers such as Muon. Fluency with a few worked numbers matters more than breadth.

## Key concepts

### Bayes' rule and base rates

P(A|B) = P(B|A)·P(A) / P(B), with P(B) expanded over all ways B can happen. When the prior is small, even an accurate test produces mostly false positives (base-rate neglect). The odds form is the fastest to compute: posterior odds = prior odds × likelihood ratio, where LR⁺ = sensitivity / false-positive rate.

### Estimation: MLE, MAP and bias

MLE maximises the likelihood; for a Gaussian it gives the sample mean and a variance estimate with divisor n, which is biased low by a factor (n−1)/n (hence ddof=1). MAP adds a log-prior: an isotropic Gaussian prior on weights is L2 regularisation with λ = σ²/τ², and a Laplace prior gives L1. Cross-entropy loss is negative log-likelihood under a categorical or Bernoulli model.

### Standard deviation, standard error and the CLT

SD describes spread of individual observations and does not shrink with n. The standard error of a mean is σ/√n; for a proportion it is √(p(1−p)/n). By the central limit theorem the mean is approximately normal, so a 95% CI is estimate ± 1.96 SE. Quadrupling n only halves the SE. The approximation breaks down on small evals: below a few hundred items, such as a 30-problem maths set, CLT intervals usually understate uncertainty and can spill outside [0, 1] or shrink to zero width at 0% or 100%, so use Wilson, exact or Bayesian (Beta) intervals, or a bootstrap.

### Hypothesis tests, power and minimum detectable effect

α is the false-positive rate you accept under the null; power (1−β) is the probability of detecting a true effect of a given size. Per-arm sample size for two proportions is roughly n ≈ (z₁₋α/₂ + z₁₋β)² · [p₁(1−p₁) + p₂(1−p₂)] / δ²; with α = 0.05 two-sided and 80% power the multiplier is (1.96 + 0.84)² ≈ 7.85. Halving the detectable effect quadruples n.

### Paired designs and variance reduction

Comparing two models on the same eval items, or the same users before and after, removes between-item variance: use McNemar's test or a paired bootstrap on per-item differences. CUPED regresses the outcome on a pre-experiment covariate; Microsoft reported about 50% variance reduction at Bing, equivalent to doubling traffic. Clustered standard errors are needed when items share a passage or users share a session. For stochastic models and agents, run several trials per item: the intraclass correlation splits variance into between-item difficulty and within-item inconsistency, and one 2025 study found it settled after 8–16 trials on structured tasks but needed 32 or more on complex reasoning tasks. With n samples per task of which c pass, the unbiased pass@k estimate is 1 − C(n−c, k)/C(n, k); plugging p̂ into 1 − (1 − p̂)^k is biased low, because that function is concave in p.

### Peeking, multiple comparisons and sequential testing

Stopping as soon as p < 0.05 inflates the false-positive rate well above 5% (Evan Miller shows ten peeks turn a nominal 1% into about 5%). Valid options: a fixed horizon, group-sequential designs with alpha spending, always-valid p-values (mSPRT), or Bayesian decision rules stated in advance. Testing many metrics or slices needs Bonferroni or false-discovery-rate control.

### Entropy, cross-entropy and KL divergence

H(p) = −Σ p log p; cross-entropy H(p,q) = −Σ p log q = H(p) + KL(p‖q). Because H(p) of the data is fixed, minimising cross-entropy equals minimising KL from data to model, which is MLE. KL is asymmetric and non-negative; forward KL is mass-covering, reverse KL mode-seeking, which matters for distillation and RLHF penalties. The ELBO is log p(x) minus KL(q(z|x) ‖ p(z|x)).

### Linear algebra and calculus for learning

Symmetric real matrices have real eigenvalues and orthogonal eigenvectors (covariance → PCA). SVD A = UΣVᵀ exists for any matrix and truncation gives the best rank-r approximation (Eckart–Young); a rank-r update to a d×d matrix needs 2dr parameters, which is LoRA's saving. The gradient of softmax cross-entropy with respect to logits is p − y; reverse-mode autodiff gets all gradients of a scalar loss for a small constant multiple of one forward pass. Orthogonalisation is now examinable too: the Muon optimiser replaces a weight matrix's momentum update G = USVᵀ with UVᵀ, the nearest semi-orthogonal matrix, computed with about five Newton–Schulz matrix iterations instead of an SVD, so every singular direction gets a step of the same size.

## Worked examples

### Base rates: how likely is a positive test to be a true positive?

A condition has prevalence 1 in 1,000. A test has 99% sensitivity and a 2% false-positive rate. A random person tests positive. What is P(condition | positive)? What if a second, independent test is also positive?

**Solution**

**Bayes' rule**

P(+) = 0.99 × 0.001 + 0.02 × 0.999 = 0.00099 + 0.01998 = 0.02097

P(D | +) = 0.00099 / 0.02097 ≈ **4.7%**

**Natural frequencies** (the intuition interviewers want): of 100,000 people, 100 have the condition
and 99 test positive; of 99,900 without it, about 1,998 test positive. Only 99 of 2,097 positives
are real.

**Second independent positive** (odds form):
- prior odds now 0.0472 / 0.9528 ≈ 0.0496
- LR⁺ = 0.99 / 0.02 = 49.5
- posterior odds ≈ 0.0496 × 49.5 ≈ 2.45 → probability 2.45 / 3.45 ≈ **71%**

Caveat: real repeat tests are rarely independent (same biology, same lab), so 71% is an upper bound.
The same arithmetic applies to fraud alerts or a classifier flagging rare policy violations.


### Sample size for an A/B test on conversion

Baseline conversion is 10%. How many users per arm do you need to detect an absolute lift to 11% with a two-sided α = 0.05 and 80% power? What would halve it?

**Solution**

z₁₋α/₂ = 1.96, z₁₋β = 0.84 → (1.96 + 0.84)² ≈ 7.85

Variance term: p₁(1−p₁) + p₂(1−p₂) = 0.10 × 0.90 + 0.11 × 0.89 = 0.0900 + 0.0979 = 0.1879

δ² = 0.01² = 0.0001

n ≈ 7.85 × 0.1879 / 0.0001 ≈ **14,750 users per arm** (about 29,500 total).

Levers:
- **CUPED / regression adjustment**: a 50% variance reduction roughly halves n.
- **Larger MDE**: detecting +2 points instead of +1 cuts n by about 4×.
- **More sensitive metric**: e.g. add-to-basket instead of purchase, if it is a validated proxy.
- **One-sided test** only if you would genuinely never act on a negative result.
Then convert n into days of traffic and run whole weeks to cover weekly seasonality.


### Is 84% versus 81% on a 200-item eval real?

A new prompt scores 84% and the old one 81% on the same 200 items. Test it unpaired and paired, assuming the new prompt fixes 14 items the old one got wrong and breaks 8 it got right. How many items would an unpaired comparison need for 80% power?

**Solution**

**Unpaired** (wrong analysis for shared items, but the usual first instinct):
- SE(84%) = √(0.84 × 0.16 / 200) ≈ 0.026; SE(81%) ≈ 0.028
- SE of the difference = √(0.026² + 0.028²) ≈ 0.038
- z = 0.03 / 0.038 ≈ 0.79 → p ≈ 0.43. Not distinguishable.

**Paired (McNemar)**: only the 22 discordant items carry information.
- χ² = (14 − 8)² / (14 + 8) = 36 / 22 ≈ 1.64 → p ≈ 0.20 (exact binomial p ≈ 0.29). Still noise.

**Items needed unpaired** at 80% power:
n ≈ 7.85 × (0.81 × 0.19 + 0.84 × 0.16) / 0.03² = 7.85 × 0.2883 / 0.0009 ≈ **2,500 per arm**.

**Paired** with an 11% discordance rate needs roughly
(1.96·√0.11 + 0.84·√(0.11 − 0.0009))² / 0.03² ≈ **960 items**, a 2.6× saving.
Also sample each item several times to separate model sampling noise from item difficulty.


## What changed recently

- **Apr 2026: Muon's orthogonalised updates reach frontier pre-training.** DeepSeek-V4, a pair of mixture-of-experts models with million-token context (the larger has 1.6T parameters), was trained with the Muon optimiser for faster convergence and more stable training, following Moonshot's 2025 result that Muon scales with roughly twice AdamW's compute efficiency. Muon's update is the orthogonal polar factor UVᵀ of the momentum matrix, approximated by Newton–Schulz iterations. Research interviewers now use it to test SVD, polar-decomposition and matrix-iteration intuition. [Source](https://arxiv.org/abs/2606.19348)
- **Jan 2026: pass@k versus pass^k becomes standard agent-eval vocabulary.** Anthropic's guide to agent evals defines pass@k as the chance of at least one success in k trials and pass^k as the chance that all k succeed, so the first rises with k while the second falls (0.75³ ≈ 42%). It recommends multiple trials per task because outputs vary between runs. Interviewers now ask which metric suits a product (one-shot coding tool versus customer-facing agent) and how to estimate each. [Source](https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents)
- **Dec 2025: Intraclass correlation for run-to-run variance in agent evals.** A December 2025 paper argued that single-run accuracy hides agent inconsistency and proposed the intraclass correlation to separate between-query variance (difficulty) from within-query variance (inconsistency), reporting values of about 0.30–0.77 on GAIA. It found the estimate stabilised after 8–16 trials on structured tasks but needed 32 or more on complex reasoning. It gives a concrete answer to "how many reruns per task do you need?" [Source](https://arxiv.org/abs/2512.06710)
- **Aug 2025: Signal-to-noise ratio as a benchmark-selection criterion.** Heineman et al. defined a benchmark's signal (how well it separates stronger from weaker models) and noise (variability between training checkpoints), and showed across 30 benchmarks and 375 models that a higher ratio makes small-scale decisions more reliable and lowers scaling-law prediction error. Cheap fixes include scoring with perplexity rather than accuracy, dropping noisy subtasks and averaging checkpoints. Interviewers use it to probe whether you can reason about measurement noise before trusting a small-model ablation. [Source](https://arxiv.org/abs/2508.13144)
- **Mar 2025: Normal-approximation error bars fail on small LLM evals.** An ICML 2025 spotlight position paper argued that CLT-based intervals, fine for benchmarks with thousands of items, dramatically understate uncertainty on small specialised ones, and recommended simple frequentist and Bayesian alternatives with a supporting library. With reasoning benchmarks such as 30-problem maths sets now headline numbers, candidates are expected to know which interval to use and why. [Source](https://arxiv.org/abs/2503.01747)

## Pitfalls

- Confusing SD with SE, reporting a CI that ignores that eval items are clustered by source document, or putting a normal-approximation interval on a 30-item benchmark.
- Reading a p-value as the probability the null is true, or a non-significant result as proof of no effect.
- Stopping an A/B test the first time p < 0.05, or slicing until something is significant.
- Using unpaired tests for two models scored on the same items, throwing away most of the power.
- Claiming deep-network training loss is convex, or that eigenvectors of any square matrix are orthogonal.
- Forgetting that the MLE of variance divides by n and is biased; the unbiased estimator uses n − 1.

## How interviewers probe it

- Mental arithmetic under time pressure: base-rate problems, binomial mean and variance, quick power calculations.
- Derivations: MLE of a Gaussian, L2 as a Gaussian prior, softmax cross-entropy gradient, the ELBO.
- Applied judgement: 'our metric moved 0.8 points, ship it?' — seeds, CIs, paired tests, equal tuning budgets.
- Experiment design follow-ups: peeking, sequential tests, CUPED, multiple metrics and guardrails.
- Linear algebra intuition: what PCA keeps, why SVD truncation is optimal, why low-rank adapters work, and what Muon's orthogonalised update does to the singular values.
- Agent and LLM eval statistics: pass@k versus pass^k under independence, the unbiased pass@k estimator from n samples, how many trials per task you need, and why a 30-question benchmark needs a different interval.

## Reading

- [Seeing Theory](https://seeing-theory.brown.edu/) (Course, 90 min, Intro): Interactive visual refresher on probability, distributions, frequentist and Bayesian inference.
- [How Not To Run an A/B Test](https://www.evanmiller.org/how-not-to-run-an-ab-test.html) (Blog, 15 min, Intro): Short, numeric explanation of why peeking inflates false positives.
- [Mathematics for Machine Learning](https://mml-book.github.io/) (Book, 360 min, Core): Free book; read the linear algebra, matrix decomposition, vector calculus and probability chapters.
- [The Matrix Calculus You Need For Deep Learning](https://arxiv.org/abs/1802.01528) (Paper, 60 min, Core): Builds Jacobians and the chain rule for vectors step by step, exactly what derivation questions need.
- [Adding Error Bars to Evals: A Statistical Approach to Language Model Evaluations](https://arxiv.org/abs/2411.00640) (Paper, 40 min, Core): Applies standard errors, paired comparisons and power analysis to LLM evals.
- [Position: Don't Use the CLT in LLM Evals With Fewer Than a Few Hundred Datapoints](https://arxiv.org/abs/2503.01747) (Paper, 30 min, Core): ICML 2025 spotlight showing why normal-approximation error bars are too narrow on small benchmarks, with frequentist and Bayesian alternatives.
- [Improving the Sensitivity of Online Controlled Experiments by Utilizing Pre-Experiment Data (CUPED)](https://exp-platform.com/Documents/2013-02-CUPED-ImprovingSensitivityOfControlledExperiments.pdf) (Paper, 45 min, Deep): The original variance-reduction method behind most experimentation platforms.
- [Always Valid Inference: Bringing Sequential Analysis to A/B Testing](https://arxiv.org/abs/1512.04922) (Paper, 50 min, Deep): Formal treatment of peeking-safe p-values and confidence intervals (mSPRT).

## Practise this topic

- [A test for a condition with prevalence 1 in 1,000 has 99% sensitivity and a 2% false-positive rate. Someone picked at random tests positive. Roughly how likely…](https://gurkanozkan.ai/learn/questions/research-bayes-and-base-rates-008.md)
- [0.2% of transactions are fraudulent. A detector flags 95% of fraud and 2% of legitimate transactions. What fraction of flagged transactions are fraud? What…](https://gurkanozkan.ai/learn/questions/mle-bayes-and-base-rates-for-fraud-alerts-18.md)
- [Baseline conversion is 10%. How many users per arm do you need to detect a 1-percentage-point lift at α=0.05 and 80% power? What levers reduce it?](https://gurkanozkan.ai/learn/questions/mle-sample-size-and-minimum-detectable-effect-50.md)
- [A PM checks the dashboard daily and stops when p < 0.05. What is wrong, and what valid alternatives exist?](https://gurkanozkan.ai/learn/questions/mle-peeking-and-sequential-testing-51.md)
- [Your new prompt scores 84% against 81% on a 200-item set. Is that real? How many items would you need?](https://gurkanozkan.ai/learn/questions/applied-llm-evl-07.md)
- [Your method beats the baseline by 0.8 points on a benchmark. What would you need to see before believing the improvement is real?](https://gurkanozkan.ai/learn/questions/research-is-a-0-8-point-gain-real-060.md)
- [Explain the difference between a sample's standard deviation and the standard error of the mean, and how each changes with sample size.](https://gurkanozkan.ai/learn/questions/mle-standard-deviation-vs-standard-error-19.md)
- [Define entropy, cross-entropy and KL divergence for discrete distributions, show how they relate, and explain why minimising cross-entropy loss equals maximum…](https://gurkanozkan.ai/learn/questions/research-entropy-cross-entropy-kl-014.md)
- [Define linear independence and matrix rank. If a fine-tuning update to a d×d weight matrix is constrained to rank r, how many parameters does it use, and what…](https://gurkanozkan.ai/learn/questions/research-rank-and-low-rank-adaptation-006.md)
- [Derive the gradient of cross-entropy loss with respect to the logits when predictions come from a softmax. How do you implement the loss so it never overflows…](https://gurkanozkan.ai/learn/questions/research-softmax-cross-entropy-gradient-025.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
