Bias and variance
偏差与方差
Separate prediction bias, training variability and fresh-response noise with an exactly enumerated experiment; explain why the identity does not force a U-shaped curve.
bias-varianceA worse fit can make a better prediction
Imagine a sensor whose readings are either −1/2 or 3/2, equally likely and independent. Its true mean is 1/2. We get only two training readings and must predict a fresh one. These numbers define a teaching experiment; they are not measurements from a real device.
One rule predicts the training average. Another predicts one third of that average, pulling it toward zero. The first rule is unbiased: across all four equally likely training sequences, its predictions average to 1/2. The second rule is biased: its predictions average to 1/6. Yet the second rule has lower expected squared error on the next reading: 7/6 instead of 3/2. Being right on average is not enough if individual fits fluctuate too much.
Bias measures the difference between an average fitted prediction and the target conditional mean. Variance measures how much that prediction changes when the training procedure is repeated. Neither is the error of one particular prediction. Deep Learning, Section 5.4.4 relates their squared-error contributions; the example here computes them without simulation noise.
Prediction error for three rules
New-response noise 1 +Squared bias 1/4 +Prediction variance 0
New-response noise 1 +Squared bias 1/9 +Prediction variance 1/18
New-response noise 1 +Squared bias 0 +Prediction variance 1/2
Specify what is random before splitting the error
Fix a query x. Write and . Let D be the random training data and, if relevant, include random initialization or sampling in the training procedure. Its fitted prediction is ; define . Assume the required second moments are finite and the new response at x is independent of the training procedure. Then
The terms are conditional noise, squared bias, and prediction variance. To derive this identity, write the residual as . After squaring, all three cross terms have expectation zero: the centered response and centered prediction have mean zero, and their independence removes their product. Averaging the identity over the intended test-input distribution gives overall expected test risk. Cornell CS4780, Lecture 12, decomposition
For the sensor, with independent equiprobable noises −1 and +1. The estimator is , with a fixed before seeing the sample. For n training readings,
Differentiate this quadratic. The best a within [0,1] is . At μ=1/2 and n=2 it is 1/3. This is an oracle choice using the true mean; it explains the trade-off but cannot be used as a data-free tuning recipe when μ is unknown.
| Fixed shrink factor a | Squared bias | Prediction variance | New-response noise | Expected test MSE | Expected training MSE |
|---|---|---|---|---|---|
| 0 | 1/4 | 0 | 1 | 5/4 | 5/4 |
| 1/3 | 1/9 | 1/18 | 1 | 7/6 | 5/6 |
| 1 | 0 | 1/2 | 1 | 3/2 | 1/2 |
The training column is different for a reason: a training label also helped determine its own prediction. It does not satisfy the independence assumption above. Using gives
Thus the unbiased sample mean has the best training fit among these choices and the worst expected test error. The gap is calculated over repetitions; one observed train/test split need not display this ordering.
Enumerate every possible training sequence
This complete program uses exact fractions. It fits all sequences of noisy labels, then averages over a separate new response. It evaluates a deliberately small known distribution, not an estimate of an unknown real-world noise floor.
from fractions import Fraction as F
from itertools import product
def exact(v):
if type(v) is not int and not isinstance(v, F):
raise ValueError("integer or Fraction required")
return F(v)
def experiment(n, mu, shrink):
# All features are identical; only independent label noise varies.
if type(n) is not int or not 1 <= n <= 12:
raise ValueError("enumeration requires 1 <= n <= 12")
mu, a = exact(mu), exact(shrink)
if not 0 <= a <= 1:
raise ValueError("shrink must be in [0,1]")
count = 2**n
s1 = s2 = training = test = F(0)
for signs in product((-1, 1), repeat=n):
labels = [mu+e for e in signs]
pred = a*sum(labels)/n
s1 += pred
s2 += pred**2
training += sum((v-pred)**2 for v in labels)/n
# A NEW, independent label has its own two possible noises.
test += sum((mu+e-pred)**2 for e in (-1, 1))/2
mean = s1/count
bias2 = (mean-mu)**2
variance = s2/count-mean**2
result = dict(mean=mean, bias2=bias2, variance=variance,
noise=F(1), train=training/count, test=test/count)
assert result["test"] == bias2+variance+1
return result
for a in (F(0), F(1,3), F(1)):
print(a, experiment(2, F(1,2), a))
r = experiment(2, F(1,2), F(1,3))
assert (r["bias2"],r["variance"],r["test"]) == (F(1,9),F(1,18),F(7,6))
assert r["train"] == F(5,6)
assert experiment(2,F(1,2),1)["train"] == F(1,2)
For each shrink factor, the program takes O(n·2ⁿ) arithmetic operations and O(n) working storage; fraction bit costs are additional. The cap of twelve samples makes the exponential enumeration explicit. Analytic formulas handle larger n cheaply; empirical repeated-fit studies usually use resampling or new datasets instead.
Change μ to four. Strong shrinkage toward zero now introduces much more error because the signal is far from the shrinkage target. Change n while keeping a=1: variance becomes 1/n. Change n while keeping a=1/3 and a nonzero μ: variance decreases, but the nonzero bias persists. These are properties of specified procedures, not of the word “simple.”
The identity is exact; a U-shaped curve is not a theorem
The decomposition does not force bias to decrease or variance to increase with parameter count. Both depend on the data distribution, sample size, model, optimizer, regularization and the quantity predicted. In particular, finite-sample bias is not defined only by what happens with infinite data. An estimator’s bias can change with n; approximation error from a restricted function class is a related but distinct idea.
The familiar U-shaped sketch is useful in some regimes, but cannot be substituted for measurements. Belkin and colleagues report double-descent curves for specified model families and datasets, including minimum-norm random-feature fits. That observation does not invalidate the squared-error identity or establish a universal advantage for larger networks. Their 2019 version, Sections 1–2 states the interpolation setup and the rule for selecting among multiple fits.
The three-term equation is for squared loss. Accuracy and zero-one classification loss do not automatically have the same decomposition. Statistical estimator bias is also distinct from social bias or group disparities; this equation alone does not assess fairness.
The “irreducible” noise term is relative to the available features and target distribution. Additional informative measurements may reduce conditional variance. A distribution shift changes the reference f and noise, so an old decomposition need not describe deployment. Leakage, optimization failure and corrupted labels can also create a large train/test gap; the gap by itself does not identify a unique cause. D2L, Sections 3.6.1–3.6.2 separates training error from the distributional quantity we want to predict.
Try to defeat an overgeneralization
- Why does the a=1/3 rule beat the unbiased rule in the sensor example? Answer: its variance falls from 1/2 to 1/18, more than compensating for squared bias 1/9. New-response noise remains one for both.
- Can the same decomposition be applied to a training label as if it were a new independent response? Answer: not without retaining the dependence terms. For n=2 and a=1, the expected training MSE is 1/2, whereas the new-response risk is 3/2.
- If μ=0, which a minimizes risk in this known toy distribution? Answer: a=0, giving risk one. This uses knowledge of the true mean; it does not authorize setting every real-world prediction to zero.
- Does a model with more parameters have to have larger variance? Answer: no. The identity imposes no monotonic dependence on parameter count. Specify the training procedure and distribution, then calculate or measure the terms.
Use repeated fits to ask a narrower question
For an actual experiment, fix the data-generating or resampling protocol, sample size, test inputs, loss and training algorithm. Record predictions from multiple fits. Their variation estimates something about that protocol; changing only the random seed measures a different source of variation from drawing new training datasets. If both vary, the law of total variance separates expected seed variance conditional on D from variance across the seed-averaged fits.
Estimating bias is harder because the true f is generally unknown. Synthetic experiments make it known, which is why they are useful for checking a claim. On real data, report validation performance and uncertainty from a defensible protocol instead of labeling two observed loss numbers as exact bias and variance. Train/validation/test splits and regularization provide the next operational steps.
Make a prediction, then check
Must an unbiased estimator have lower prediction MSE than a biased one?
Learning objectives
- Derive the squared prediction-error decomposition under explicit independence and finite-second-moment conditions.
- Exactly compute training and test errors for shrinkage rules, distinguishing finite-sample bias, variability and noise.
Prerequisites & connections
- Expectation and variance
- Independence and conditional independence
- Mean squared error
- Supervised learning
References
- Deep Learning — Machine Learning Basics, §5.4
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016 - Cornell CS4780 Spring 2024 — Lecture 12: Bias-Variance Tradeoff
Cornell University · 2024 - Reconciling modern machine learning practice and the bias-variance trade-off
Mikhail Belkin; Daniel Hsu; Siyuan Ma; Soumik Mandal · 2019 - Dive into Deep Learning — 3.6 Generalization
Aston Zhang; Zachary C. Lipton; Mu Li; Alexander J. Smola · 2023
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: source locations, independent numerical verification and full bilingual rereading; some drafts by an agent reviewed by the parent; no independent human peer review.
- Independently verified54 enumerated cases using binomial count weights, including training error and test gap2a/n; checked oracle shrinkage by completing the square and the heteroskedastic/seed total-variance decomposition.
- Figure stores exact rational error components and is compared with the program distribution; oracle a uses the true mean and is not a data-free tuning rule for an unknown mean.
- The parent executed all19 independent learning-theory/neural tests. Structure checks compare bilingual anchors,display equations,code and sources; parent reread four answers and arguments. Historical articles make no code-execution claim.
Source locations checked:
- Deep Learning — Machine Learning Basics, §5.4 · Official chapter HTML text retrieved after web-reader size rejection; §5.4.4, printed127–128, equations5.53–5.54. Estimator MSE decomposition; curve illustration is not a general monotonic theorem. No figure or wording copied.
- Cornell CS4780 Spring 2024 — Lecture 12: Bias-Variance Tradeoff · Lecture12, setup and decomposition, lines8–24; independent train/test product distribution and squared loss. Finite-sample bias is used, not the later informal infinite-data definition; training-gap diagnoses qualified.
- Reconciling modern machine learning practice and the bias-variance trade-off · arXivv2 2019-09-10, Sections1–2, especially random-feature minimum-norm selection at lines93–105. Only qualitative reported double-descent evidence, not benchmark replication or universal claim.
- Dive into Deep Learning — 3.6 Generalization · Sections3.6.1–3.6.2: training versus generalization error and finite-data evaluation; read current1.0.3 official text.
Related topics