Bias-Variance, Calibration, and Drift: A Production ML Walkthrough
Machine LearningModel answerLast updated
Explain the bias-variance decomposition, what a calibrated probability means and how to repair one, and how concept drift differs from covariate shift in production.
Three Core Concepts for a High-Stakes ML Role
You're interviewing for a machine learning engineering role on a team that ships predictive models into settings where wrong probabilities have real costs. The interviewer wants you to explain three ideas and connect them to what happens after a model goes live.
-
Bias and variance. Describe what underfitting and overfitting look like, and how changing model complexity moves the bias and variance parts of expected test error.
-
Calibration. Say a classifier assigns 0.8 to an example. What does it mean for that score to be well calibrated? Why can a model have excellent ranking quality (for example, a high AUC-ROC) and still be poorly calibrated? How would you correct the calibration?
-
Drift. Distinguish concept drift from data drift (covariate shift). Give a concrete example of each and describe how you would detect them in a live system.
Tie the theory back to operations. In particular, explain what signals should trigger a retrain, and what should not.
Hints
Hint 1
Write expected squared error at a fixed input as bias squared plus variance plus irreducible noise, and ask which term each kind of model complexity moves.
Hint 2
Separate ranking quality from probability quality: think about what happens to AUC when every score is passed through a strictly increasing function.
Hint 3
Ask which factor of the joint distribution P(X, Y) changes under each kind of drift, and whether you can detect that change without seeing labels.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Bias-Variance, Calibration, and Drift
A strong answer does three things. It states the math precisely, explains why each quantity matters after deployment, and turns each idea into a monitoring signal or a retraining rule.
1. Bias and Variance
Setup. Assume $y = f(x) + \varepsilon$, where $\mathbb{E}[\varepsilon] = 0$ and $\text{Var}(\varepsilon) = \sigma^2$. Let $\hat f_D$ be the model fit on a random training set $D$. At a fixed input $x$, the expected squared test error decomposes as:
$$ \mathbb{E}_{D,\varepsilon}\big[(y - \hat f_D(x))^2\big] = \underbrace{\big(f(x) - \mathbb{E}D[\hat f_D(x)]\big)^2}{\text{Bias}^2} + \underbrace{\mathbb{E}D\big[(\hat f_D(x) - \mathbb{E}D[\hat f_D(x)])^2\big]}{\text{Variance}} + \underbrace{\sigma^2}{\text{irreducible}} $$
The derivation adds and subtracts $\mathbb{E}_D[\hat f_D(x)]$. The cross terms vanish because the noise is independent of the training set and has mean zero.
- Bias comes from restrictive assumptions. Fitting a straight line to a curved relationship is biased everywhere, on every training set you could draw.
- Variance measures how much predictions move when the training sample changes.
- Irreducible noise is a floor that no predictor can go below.
Underfitting and overfitting show up in the gap between training and validation error:
| Training error | Validation error | Dominant term | |
|---|---|---|---|
| Underfit | High | High, close to training | Bias |
| Overfit | Low | Much higher than training | Variance |
Effect of complexity. As capacity increases (more features, deeper trees, weaker regularization), bias usually falls and variance usually rises. Test error often follows a U-shape, with the minimum at the point where the two terms balance.
There is a modern caveat. Very overparameterized neural networks can exhibit double descent: test error rises near the interpolation threshold and then falls again as capacity keeps growing. Implicit regularization from SGD and the architecture can keep variance under control. So "more parameters means more variance" is a useful heuristic, not a law.
Levers:
- To reduce variance: collect more data, add regularization (L2, dropout, early stopping), or use bagging.
- To reduce bias: add features, increase capacity, or use boosting.
2. Calibration
Definition. A model is calibrated when its predicted probabilities match observed frequencies:
$$ P(Y = 1 \mid \hat p(X) = p) = p \quad \text{for all } p. $$
Among all cases scored 0.8, about 80% should turn out positive.
Checking calibration:
- Reliability diagram. Bin predictions, then plot the mean predicted probability against the observed positive rate in each bin. A calibrated model falls on the diagonal.
- Expected Calibration Error (ECE). This is the bin-weighted average gap between confidence and accuracy: $$\text{ECE} = \sum_b \frac{|B_b|}{n},\big|\text{acc}(B_b) - \text{conf}(B_b)\big|$$
- Proper scoring rules. Report the Brier score or log-loss. These reward both calibration and discrimination, so they can't be gamed by one of them alone.
Why high AUC doesn't imply good calibration. AUC depends only on the ordering of scores. It is unchanged by any strictly increasing transformation. If you square every score, AUC stays the same, but the numbers are no longer probabilities.
Common sources of miscalibration:
- Deep networks trained with cross-entropy. After they fit the training labels, they keep pushing logits toward extremes, which makes them overconfident.
- Boosted trees and SVMs. Their raw outputs are margins or scores, not probabilities.
- Naive Bayes. The independence assumption multiplies evidence together and pushes outputs toward 0 or 1.
- Resampling or class weighting. These change the effective base rate the model learns from.
Fixes. All of these are post-hoc. Fit them on a held-out calibration set, never on the training data.
- Platt scaling: fit a logistic regression on the scores. It's parametric and works well with little data.
- Isotonic regression: fit a monotone, non-parametric mapping. It is more flexible but needs more data and can overfit small samples.
- Temperature scaling: learn one scalar $T$ and apply $\text{softmax}(z/T)$ to the logits. This is the standard fix for neural networks. It preserves ranking, so AUC and accuracy are unchanged.
- Prior correction: if you resampled classes, shift the logit intercept by $\log\frac{\pi_{\text{true}}/(1-\pi_{\text{true}})}{\pi_{\text{train}}/(1-\pi_{\text{train}})}$.
Why it matters. Thresholds, expected-cost decisions, and downstream systems that combine probabilities all assume calibrated inputs. A model with AUC 0.95 that outputs 0.8 for cases that are really 0.5 will misallocate resources even though its ranking is excellent.
3. Drift
Factor the joint distribution as $P(X, Y) = P(X),P(Y \mid X)$. Each type of drift changes a different factor.
| Type | What changes | Example | Labels needed to detect? |
|---|---|---|---|
| Data drift (covariate shift) | $P(X)$, with $P(Y\mid X)$ fixed | A loan model trained mostly on salaried applicants starts receiving many gig-economy applicants. The risk rules are the same, but these inputs sit in regions with little training data. | No |
| Concept drift | $P(Y \mid X)$ | Fraudsters change tactics, so transaction patterns that used to be benign now signal fraud. | Yes, or proxies |
| Label (prior) shift | $P(Y)$, with $P(X\mid Y)$ fixed | Disease prevalence rises during an outbreak. | Partially |
The distinction matters because covariate shift can be detected without labels, while concept drift requires outcomes or proxies.
Detection strategy:
-
Input monitoring (label-free, near real time).
- Per-feature tests: Population Stability Index (PSI, where values above 0.2 are a common alarm), the KS test, or Jensen–Shannon divergence.
- Multivariate tests: MMD, or a domain classifier trained to distinguish the reference window from live traffic. An AUC well above 0.5 indicates drift.
- Monitor the distribution of model outputs too. A shifting score histogram is a cheap early warning.
-
Performance monitoring (needs labels, often delayed).
- Track AUC, log-loss, and ECE on labeled traffic as outcomes arrive.
- Run sequential change detectors on the error stream, such as DDM, ADWIN, or Page–Hinkley.
-
Proxies when labels are slow. Chargebacks, complaints, manual review results, or a small randomly sampled set of labeled cases.
When to retrain:
- Input drift with stable performance: investigate, but don't retrain automatically. The model may generalize well to the new region.
- Drop in labeled performance: retrain on recent data. If the change looks like concept drift, weight or window the training data toward recent examples.
- Calibration-only degradation: refitting the calibrator is often enough and is much cheaper than retraining.
- Gate every retrain: require a shadow or champion–challenger comparison before promoting a new model.
- Scheduled retraining is a reasonable baseline when drift is known to be continuous, such as seasonal demand.
Common Mistakes
- Calling every change in inputs "concept drift." Covariate shift with stable $P(Y\mid X)$ often needs no retrain.
- Calibrating on the training set, which hides overfitting and produces miscalibrated outputs in production.
- Treating AUC as evidence that probabilities are usable.
- Retraining on every alert. Without a gated evaluation, you can deploy a worse model.