Ten problems on bias and variance: the mean squared error of an estimator split into squared bias plus variance, the sample mean and a shrunken mean that beats it, the three-term decomposition of expected test error with the noise floor, the one-dimensional least-squares estimator and its ridge version with bias, variance and the λ that minimises their sum, how the two terms move with λ, why averaging models cuts variance but not bias and where correlation puts the floor, the variance estimator with the smallest error, and nearest-neighbour regression where k trades bias against variance, with worked solutions and the mistakes that prefer unbiased by reflex, apply the decomposition to training error, guess the ridge variance by analogy, forget the noise term, or divide the variance of correlated models by their number.
Before you start
An estimator can be wrong in two ways: on average, which is bias, and from one dataset to the next, which is variance. Mean squared error is the sum of the square of the first and the second, and almost every design decision in machine learning, regularisation strength, model size, how many neighbours, how many models to average, moves one term up and the other down. These ten problems prove the decomposition for a scalar estimator and for a prediction at a point, where a third term, the noise, appears; work it out for the sample mean and show that shrinking it towards zero lowers the error; do the same for the one-dimensional least-squares slope and its ridge version, finding the regularisation that minimises the total; show how the two terms move with the regulariser; compute what averaging models does to each term; find the variance estimator with the smallest error, which is neither the unbiased one nor the maximum-likelihood one; and end with nearest-neighbour regression, where the number of neighbours is the knob. The five mistakes at the end are the ones that sound like good statistics: unbiased taken to mean best, the decomposition applied to the training set, a ridge variance written by analogy, the noise term dropped, and the variance of an average divided by the number of models when the models are correlated.
An estimator θ^ is a function of a random sample, so it is a random variable; θ is the fixed quantity it estimates. Its bias is ,bias(θ^)=E[θ^]−θ, its variance is Var(θ^)=E[(θ^−E[θ^])2] and its mean squared error is MSE(θ^)=E[(θ^−θ)2] (the maximum-likelihood page). E and Var are over the sample; the variance page's rules ,E[aX+b]=aE[X]+b,Var(aX)=a2Var(X) and Var(∑nXn)=∑nVar(Xn) for independent Xn are used throughout.
A sample x1,…,xN is independent and identically distributed (i.i.d.) with mean μ and variance ;σ2;xˉ=N1∑nxn is the sample mean and .S=∑n(xn−xˉ)2. For Gaussian data, S/σ2 has a chi-square distribution with N−1 degrees of freedom, whose mean is N−1 and variance ;2(N−1); this is taken as given.
Regression data are y=f(x)+ε with ,E[ε]=0,,Var(ε)=σ2, and the noise on different points independent. A learner trained on a dataset D produces the prediction ;f^D(x);ED is the expectation over datasets and VarD the variance across them. A fresh test point has its own noise ,ε, independent of .D.
The one-dimensional linear model has fixed inputs ,x1,…,xN, true slope ,w, observations ,yn=wxn+εn, and .s=∑nxn2. Least squares gives w^=∑nxnyn/s and ridge with penalty λ≥0 gives ,w^λ=∑nxnyn/(s+λ), the minimiser of ∑n(yn−wxn)2+λw2 (the regression page).
1 is the all-ones vector, Σ a covariance matrix and ρ a correlation coefficient. k-nearest-neighbour regression predicts ,f^(x)=k1∑j∈Nk(x)yj, the mean of the k training responses nearest to .x.
Show that for any estimator θ^ of a fixed ,θ,.MSE(θ^)=bias(θ^)2+Var(θ^).
··
For an i.i.d. sample with mean μ and variance ,σ2, compute the bias, variance and MSE of the sample mean .xˉ. Then do the same for the shrunken estimator cxˉ with ,0≤c≤1, find the c∗ that minimises its MSE, and evaluate for ,μ=1,,σ2=1,.N=4.
··
For a fixed test input x with y=f(x)+ε and a learner ,f^D, show that .ED,ε[(y−f^D(x))2]=σ2+(ED[f^D(x)]−f(x))2+VarD(f^D(x)). Which term can a better learner not reduce?
·
For the one-dimensional model yn=wxn+εn with fixed inputs, show that the least-squares estimator w^=∑nxnyn/s satisfies ,w^=w+∑nxnεn/s, that it is unbiased, and that .Var(w^)=σ2/s.
··
For ridge, ,w^λ=∑nxnyn/(s+λ), show that ,w^λ=s+λsw^, and compute its bias, variance and MSE as functions of .λ.
···
Find the λ∗ that minimises MSE(w^λ) and the minimum value. Show that λ∗>0 always, so some ridge penalty beats least squares, and evaluate for ,w=1,,σ2=1,.s=4.
··
Show that bias(w^λ)2 is increasing in λ and Var(w^λ) is decreasing, by computing their derivatives, and find their limits as .λ→∞. At what λ are the two terms equal?
··
B predictors f^1(x),…,f^B(x) each have mean ,m, variance v and pairwise correlation .ρ. Show that their average fˉ(x)=B1∑bf^b(x) has mean ,m, so the bias is unchanged, and variance .ρv+B(1−ρ)v. What are the two limits ρ=0 and ?B→∞?
···
For Gaussian data consider the estimators cS of ,σ2, where .S=∑n(xn−xˉ)2. Compute bias, variance and MSE as functions of ,c, show that the MSE is minimised at ,c∗=1/(N+1), and compare the MSEs of S/(N−1) (unbiased), S/N (maximum likelihood) and S/(N+1) for .N=5.
···
Training inputs lie on a grid with spacing ,h,,f(x)=ax2, and k-nearest-neighbour regression with k=2m+1 uses the m grid points on each side of a query x that is itself a grid point. Show that the prediction has variance σ2/k and bias ,ah212k2−1, write the MSE above the noise floor, and find the best k among {1,3,5,7,9} for ,a=1,,σ2=1,.h=41.
Answers
MSE(θ^)=bias(θ^)2+Var(θ^)
:xˉ: bias ,0, variance ,σ2/N, MSE ;σ2/N;:cxˉ: bias ,(c−1)μ, variance ,c2σ2/N, MSE ,(1−c)2μ2+c2σ2/N, minimised at ;c∗=μ2+σ2/Nμ2; for ,μ=1,,σ2=1,:N=4:c∗=0.8 and MSE 0.2 against 0.25
,E[(y−f^D(x))2]=σ2+bias2+variance, with bias=ED[f^D(x)]−f(x) and ;variance=VarD(f^D(x)); the σ2 cannot be reduced
;w^=w+∑nxnεn/s;;bias=0;,Var(w^)=σ2/s, so MSE(w^)=σ2/s
λ∗=σ2/w2 with ;MSE(λ∗)=s+σ2/w2σ2<sσ2; for ,w=1,,σ2=1,:s=4:,λ∗=1, MSE 0.2 against 0.25
,dλdbias2=(s+λ)32λsw2>0,;dλdVar=−(s+λ)32σ2s<0; limits w2 and ;0; the terms are equal at λ=σs/w
E[fˉ]=m (bias unchanged); ;Var(fˉ)=ρv+B(1−ρ)v; for ρ=0 it is ,v/B, and as B→∞ it tends to ρv
,MSE(cS)=σ4[(c(N−1)−1)2+2c2(N−1)], minimised at c∗=N+11 with ;MSE=N+12σ4; for :N=5:S/(N−1) scores ,0.5σ4,S/N scores ,0.36σ4,S/(N+1) scores 0.333σ4
,Var=σ2/k,,bias=ah2(k2−1)/12,;MSE−σ2=kσ2+a2h4144(k2−1)2; for ,a=1,,σ2=1,h=41 the best of {1,3,5,7,9} is ,k=7, with 0.2054
Worked solutions
Problem 1
Show that for any estimator θ^ of a fixed ,θ,.MSE(θ^)=bias(θ^)2+Var(θ^).
Let .m=E[θ^]. Then .θ^−θ=(θ^−m)+(m−θ).Add and subtract the mean of the estimator; the second bracket is the bias, a constant.
.(θ^−θ)2=(θ^−m)2+2(θ^−m)(m−θ)+(m−θ)2.Expand the square.
.E[(θ^−m)(m−θ)]=(m−θ)E[θ^−m]=(m−θ)⋅0.m−θ is a constant and comes out; E[θ^]−m=0 by the definition of .m.
.E[(θ^−θ)2]=E[(θ^−m)2]+(m−θ)2=Var(θ^)+bias(θ^)2.Take expectations of step 2; the cross term vanishes by step 3; the remaining terms are the definitions.
MSE(θ^)=bias(θ^)2+Var(θ^)The error splits into a systematic part, how far the average estimate sits from the truth, and a random part, how much the estimate moves from sample to sample, and the two add because the cross term averages out. Nothing about the distribution was used, only that θ is fixed and θ^ has a mean and a variance. The decomposition is an identity, not an inequality, so lowering the MSE means lowering the sum, and Problems 2, 6 and 9 all do it by accepting some bias for a larger drop in variance; Mistake 1 refuses the trade.
Problem 2
For an i.i.d. sample with mean μ and variance ,σ2, compute the bias, variance and MSE of the sample mean .xˉ. Then do the same for the shrunken estimator cxˉ with ,0≤c≤1, find the c∗ that minimises its MSE, and evaluate for ,μ=1,,σ2=1,.N=4.
,E[xˉ]=N1∑nE[xn]=μ, so .bias(xˉ)=0.Linearity of expectation; every xn has mean .μ.
,Var(xˉ)=N21∑nVar(xn)=Nσ2, so .MSE(xˉ)=Nσ2.Independence makes the variance of the sum the sum of the variances; Var(aX)=a2Var(X) with ;a=1/N; Problem 1 with zero bias.
,E[cxˉ]=cμ, so ;bias(cxˉ)=(c−1)μ;.Var(cxˉ)=c2σ2/N.Scaling by the constant c scales the mean by c and the variance by .c2.
.MSE(cxˉ)=(1−c)2μ2+c2Nσ2.Problem 1.
,dcdMSE=−2(1−c)μ2+2cNσ2=0⟺c∗=μ2+σ2/Nμ2, a minimum since the second derivative .2μ2+2σ2/N>0.Differentiate the quadratic in c and solve; it is convex, so the stationary point is the minimum.
,μ=1,,σ2=1,:N=4:,c∗=1+1/41=0.8,.MSE(0.8xˉ)=0.04⋅1+0.64⋅0.25=0.2<0.25=MSE(xˉ).Step 5, then step 4 with :c=0.8: bias ,−0.2, variance .0.16.
:xˉ: bias ,0, variance ,σ2/N, MSE ;σ2/N;:cxˉ: bias ,(c−1)μ, variance ,c2σ2/N, MSE ,(1−c)2μ2+c2σ2/N, minimised at ;c∗=μ2+σ2/Nμ2; for ,μ=1,,σ2=1,:N=4:c∗=0.8 and MSE 0.2 against 0.25Shrinking towards zero trades a bias of 0.2 for a variance cut from 0.25 to ,0.16, and wins. The catch is that c∗ depends on ,μ, the thing being estimated, so it is not an estimator one can use directly; it says the unbiased choice is not the floor, and that any prior knowledge of the size of μ (here, that μ2 is comparable to )σ2/N) can be spent. Ridge regression in Problem 6 is the same calculation with the same answer, and the Bayesian posterior mean under a Gaussian prior lands on exactly c∗xˉ with μ2 replaced by the prior variance.
Problem 3
For a fixed test input x with y=f(x)+ε and a learner ,f^D, show that .ED,ε[(y−f^D(x))2]=σ2+(ED[f^D(x)]−f(x))2+VarD(f^D(x)). Which term can a better learner not reduce?
.y−f^D(x)=ε+(f(x)−f^D(x)).Substitute y=f(x)+ε and regroup.
.(y−f^D(x))2=ε2+2ε(f(x)−f^D(x))+(f(x)−f^D(x))2.Expand the square.
E[ε2]=σ2 and .E[ε(f(x)−f^D(x))]=E[ε]ED[f(x)−f^D(x)]=0.ε has mean zero and variance ;σ2; the test noise is independent of the training set ,D, so the expectation of the product is the product of the expectations (the variance page).
.ED[(f(x)−f^D(x))2]=(ED[f^D(x)]−f(x))2+VarD(f^D(x)).Problem 1 with ,θ^=f^D(x), an estimator of the fixed number .θ=f(x).
,E[(y−f^D(x))2]=σ2+bias2+variance, with bias=ED[f^D(x)]−f(x) and ;variance=VarD(f^D(x)); the σ2 cannot be reducedThe expected test error at a point has a floor, the noise variance, that no learner reaches: even f^D=f exactly scores σ2 (Mistake 4). Above the floor sit the two terms of Problem 1 for the learner regarded as an estimator of ;f(x); averaging over x gives the usual statement about test error. Step 3 used that the test noise is independent of ,D, and that is what fails on the training set, where the same εn sits in yn and in f^D (Mistake 2). The check evaluates the left side exactly for the linear model of Problems 4 and 5, where f^D(x)=w^x is Gaussian, and compares it with the three terms.
Problem 4
For the one-dimensional model yn=wxn+εn with fixed inputs, show that the least-squares estimator w^=∑nxnyn/s satisfies ,w^=w+∑nxnεn/s, that it is unbiased, and that .Var(w^)=σ2/s.
.∑nxnyn=∑nxn(wxn+εn)=ws+∑nxnεn.Substitute the model and use .∑nxn2=s.
.w^=sws+∑nxnεn=w+s∑nxnεn.Divide by .s.
.E[w^]=w+s∑nxnE[εn]=w.The xn are fixed and every εn has mean zero.
.Var(w^)=s21∑nxn2Var(εn)=s2σ2s=sσ2.Independent noise: the variance of ∑nxnεn is ;∑nxn2σ2; then Var(aX)=a2Var(X) with .a=1/s.
;w^=w+∑nxnεn/s;;bias=0;,Var(w^)=σ2/s, so MSE(w^)=σ2/sThe estimator is the truth plus a weighted average of the noise, and its variance falls as s=∑nxn2 grows: more points, or points farther from the origin, pin the slope down. This is the scalar case of the least-squares page's ,Cov(w^)=σ2(X⊤X)−1, with .X⊤X=s. The regression page shows that least squares is also the maximum-likelihood estimator under Gaussian noise, and the MLE page's variance estimator is biased for the same structural reason that Problem 9 revisits; the slope estimator itself is not.
Problem 5
For ridge, ,w^λ=∑nxnyn/(s+λ), show that ,w^λ=s+λsw^, and compute its bias, variance and MSE as functions of .λ.
.w^λ=s+λ∑nxnyn=s+λs⋅s∑nxnyn=s+λsw^.Multiply and divide by .s.
,E[w^λ]=s+λsw, so .bias(w^λ)=s+λsw−w=−s+λλw.Problem 4's E[w^]=w scaled by the constant; .s+λs−1=−s+λλ.
.Var(w^λ)=(s+λs)2sσ2=(s+λ)2σ2s.Var(aX)=a2Var(X) with Problem 4's variance.
.MSE(w^λ)=(s+λ)2λ2w2+(s+λ)2σ2s=(s+λ)2λ2w2+σ2s.Problem 1; common denominator.
;w^λ=s+λsw^;;bias=−s+λλw;;Var=(s+λ)2σ2s;MSE=(s+λ)2λ2w2+σ2sRidge is Problem 2's shrinkage with :c=s/(s+λ): the estimate is pulled towards zero by a factor that the data size s and the penalty λ fight over, the bias is the part of w lost to the pull, and the variance is cut by .c2. At λ=0 everything reduces to Problem 4; as λ→∞ the estimate goes to ,0, with bias −w and no variance. The variance is σ2s/(s+λ)2 and not σ2/(s+λ) (Mistake 3), a distinction that matters for everything in Problems 6 and 7.
Problem 6
Find the λ∗ that minimises MSE(w^λ) and the minimum value. Show that λ∗>0 always, so some ridge penalty beats least squares, and evaluate for ,w=1,,σ2=1,.s=4.
MSE(λ)=v(λ)u(λ) with u=λ2w2+σ2s and ;v=(s+λ)2;u′=2λw2 and .v′=2(s+λ).Name the pieces for the quotient rule.
.dλdMSE=v2u′v−uv′=(s+λ)42(s+λ)[λw2(s+λ)−λ2w2−σ2s]=(s+λ)32s(λw2−σ2).Quotient rule; factor 2(s+λ) from the numerator; inside the bracket .λw2s+λ2w2−λ2w2−σ2s=s(λw2−σ2).
The derivative is negative for λ<σ2/w2 and positive for ,λ>σ2/w2, so λ∗=w2σ2 is the minimum.The sign of step 2 is the sign of ;λw2−σ2; the function decreases then increases.
.MSE(λ∗)=(s+σ2/w2)2σ4/w2+σ2s=(s+σ2/w2)2σ2(s+σ2/w2)=s+σ2/w2σ2.Substitute ;λ∗; the numerator is σ2 times the base of the denominator.
λ∗=σ2/w2>0 whenever ,σ2>0, and .s+σ2/w2σ2<sσ2=MSE(w^).A positive number divided by ;w2; a larger denominator.
,w=1,,σ2=1,:s=4:,λ∗=1,MSE(λ∗)=4+11=0.2 against ;MSE(w^)=0.25; at λ∗=1 the bias is −0.2 and the variance .4/25=0.16.Steps 3 and 4; Problem 5's bias and variance at .λ=1.
λ∗=σ2/w2 with ;MSE(λ∗)=s+σ2/w2σ2<sσ2; for ,w=1,,σ2=1,:s=4:,λ∗=1, MSE 0.2 against 0.25The best penalty is the noise-to-signal ratio ,σ2/w2, and it does not depend on :s: more data does not change the right ,λ, it makes the shrinkage factor s/(s+λ) closer to 1 so that the penalty matters less. The numbers are Problem 2's exactly, because w^λ=cw^ with c=s/(s+λ) and λ∗ corresponds to .c∗=w2/(w2+σ2/s). In the Bayesian reading, λ=σ2/τ2 is the ridge penalty that makes the posterior mean under the prior ,w∼N(0,τ2), and λ∗ is the prior whose variance matches .w2. As in Problem 2, λ∗ needs ,w, so in practice it is chosen by cross-validation, which estimates the MSE curve of Problem 7 from the data.
Problem 7
Show that bias(w^λ)2 is increasing in λ and Var(w^λ) is decreasing, by computing their derivatives, and find their limits as .λ→∞. At what λ are the two terms equal?
bias2=(s+λ)2λ2w2 and dλdbias2=w2⋅(s+λ)42λ(s+λ)2−λ2⋅2(s+λ)=(s+λ)32λsw2>0 for .λ>0.Quotient rule; factor 2λ(s+λ) from the numerator, leaving .(s+λ)−λ=s.
Var=(s+λ)2σ2s and .dλdVar=−(s+λ)32σ2s<0.Power rule on .(s+λ)−2.
As :λ→∞:bias2→w2 and .Var→0.λ2/(s+λ)2→1 and .s/(s+λ)2→0.
.bias2=Var⟺λ2w2=σ2s⟺λ=wσs.Equate the numerators, which share the denominator; take the positive root.
,dλdbias2=(s+λ)32λsw2>0,;dλdVar=−(s+λ)32σ2s<0; limits w2 and ;0; the terms are equal at λ=σs/wThis is the picture behind every regularisation plot: a rising bias curve, a falling variance curve and a U-shaped sum. Adding the two derivatives gives ,(s+λ)32s(λw2−σ2), Problem 6's derivative, and the sum is minimised where the two slopes cancel, at ,λ∗=σ2/w2, which is not where the curves cross: for Problem 6's numbers they cross at λ=2 while the minimum is at ,λ=1, where the variance term ()0.16) is still four times the squared bias ().0.04). The same shape appears with model size, training time and the number of neighbours (Problem 10) as the knob.
Problem 8
B predictors f^1(x),…,f^B(x) each have mean ,m, variance v and pairwise correlation .ρ. Show that their average fˉ(x)=B1∑bf^b(x) has mean ,m, so the bias is unchanged, and variance .ρv+B(1−ρ)v. What are the two limits ρ=0 and ?B→∞?
.E[fˉ]=B1∑bE[f^b]=B1⋅Bm=m.Linearity; every predictor has the same mean. The bias m−f(x) is therefore the same as each member's.
Let z=(f^1,…,f^B)⊤ with covariance ,Σ,Σbb=v and Σbb′=ρv for .b=b′. Then fˉ=B11⊤z and .Var(fˉ)=B211⊤Σ1.The variance page's Cov(Az)=AΣA⊤ with the 1×B matrix .A=B11⊤.
.1⊤Σ1=∑b,b′Σbb′=Bv+B(B−1)ρv.B diagonal entries equal to v and B(B−1) off-diagonal entries equal to .ρv.
.Var(fˉ)=B2Bv+B(B−1)ρv=Bv+(B−1)ρv=ρv+B(1−ρ)v.Divide by ;B2; split .(B−1)ρv=Bρv−ρv.
E[fˉ]=m (bias unchanged); ;Var(fˉ)=ρv+B(1−ρ)v; for ρ=0 it is ,v/B, and as B→∞ it tends to ρvAveraging models attacks only the variance term of Problem 3, and only the part of it that is not shared: with independent members the variance falls like 1/B (the variance page's sample mean again), and with correlated members it stops at the floor ρv however many are averaged (Mistake 5). Bagging trains members on bootstrap resamples to make them differ, and random forests decorrelate them further by restricting each split to a random subset of features, lowering ρ at the cost of a little bias; the Jensen page's ambiguity decomposition is the same conclusion reached for one dataset rather than in expectation. Boosting is the opposite strategy: it attacks the bias term by fitting each new model to the residual of the current average.
Problem 9
For Gaussian data consider the estimators cS of ,σ2, where .S=∑n(xn−xˉ)2. Compute bias, variance and MSE as functions of ,c, show that the MSE is minimised at ,c∗=1/(N+1), and compare the MSEs of S/(N−1) (unbiased), S/N (maximum likelihood) and S/(N+1) for .N=5.
E[S]=(N−1)σ2 and .Var(S)=2(N−1)σ4.S/σ2 is chi-square with N−1 degrees of freedom, with mean N−1 and variance ;2(N−1); scaling by σ2 scales the mean by σ2 and the variance by .σ4.
bias(cS)=c(N−1)σ2−σ2=(c(N−1)−1)σ2 and .Var(cS)=2c2(N−1)σ4.Scale step 1 by ;c; subtract the target .σ2.
.MSE(cS)=σ4[(c(N−1)−1)2+2c2(N−1)].Problem 1.
.dcdMSE=σ4[2(N−1)(c(N−1)−1)+4c(N−1)]=2(N−1)σ4[c(N−1)−1+2c]=2(N−1)σ4[c(N+1)−1].Differentiate the quadratic in ;c; collect the terms in .c.
,c∗=N+11, a minimum since the MSE is a convex quadratic in ;c; there ,bias=−N+12σ2,Var=(N+1)22(N−1)σ4 and .MSE=(N+1)2σ4(4+2(N−1))=N+12σ4.Set step 4 to zero; substitute c∗ into step 2 and add.
:c=N−11: bias ,0,.MSE=N−12σ4.:c=N1: bias ,−Nσ2,.MSE=σ4[N21+N22(N−1)]=N2(2N−1)σ4.Step 3 at the two values; .(NN−1−1)2=N21.
,N=5, in units of :σ4:S/4 gives ;42=0.5;S/5 gives ;259=0.36;S/6 gives .62≈0.333.Steps 5 and 6 with .N=5.
,MSE(cS)=σ4[(c(N−1)−1)2+2c2(N−1)], minimised at c∗=N+11 with ;MSE=N+12σ4; for :N=5:S/(N−1) scores ,0.5σ4,S/N scores ,0.36σ4,S/(N+1) scores 0.333σ4The unbiased estimator has the largest error of the three: its lack of bias is bought with variance, and the maximum-likelihood 1/N already does better; the best divisor is ,N+1, which nobody uses because the gain over 1/N is small and the argument requires Gaussian data. The MLE page's Problem 5 explains the bias of ;S/N; this problem shows that bias was not the thing to minimise. The check evaluates E[S] and E[S2] exactly by quadrature for small ,N, so the chi-square facts are verified rather than assumed.
Problem 10
Training inputs lie on a grid with spacing ,h,,f(x)=ax2, and k-nearest-neighbour regression with k=2m+1 uses the m grid points on each side of a query x that is itself a grid point. Show that the prediction has variance σ2/k and bias ,ah212k2−1, write the MSE above the noise floor, and find the best k among {1,3,5,7,9} for ,a=1,,σ2=1,.h=41.
,f^(x)=k1∑j=−mm(f(x+jh)+εj), so .Var(f^(x))=k21⋅kσ2=kσ2.The k neighbours are the grid points ;x+jh; their noises are independent with variance ,σ2, and the average of k of them has variance .σ2/k.
.E[f^(x)]=k1∑j=−mma(x+jh)2=ax2+k2axh∑jj+kah2∑jj2=ax2+kah2∑j=−mmj2.Expand the square; ∑j=−mmj=0 by symmetry.
,∑j=−mmj2=2⋅6m(m+1)(2m+1)=3m(m+1)k, so .bias=E[f^(x)]−ax2=3ah2m(m+1).The sum of the first m squares, doubled for the negative side; 2m+1=k cancels the .1/k.
m=2k−1 gives ,m(m+1)=4(k−1)(k+1)=4k2−1, so .bias=ah212k2−1.Substitute and simplify.
.MSE−σ2=kσ2+a2h4144(k2−1)2.Problem 3's bias squared plus variance.
With ,a=1,,σ2=1,h=41 ():h4=2561)::k=1:;1;:k=3:;0.3333+3686464=0.3351;:k=5:;0.2+36864576=0.2156;:k=7:;0.1429+368642304=0.2054;:k=9:.0.1111+368646400=0.2847.Step 5 term by term; .144⋅256=36864.
,Var=σ2/k,,bias=ah2(k2−1)/12,;MSE−σ2=kσ2+a2h4144(k2−1)2; for ,a=1,,σ2=1,h=41 the best of {1,3,5,7,9} is ,k=7, with 0.2054k=1 has no bias and all the variance; growing k averages the noise down as 1/k but reaches farther from ,x, where the curvature a of f makes the neighbours' average drift above ,f(x), and that bias grows like .k2. The best k depends on everything: more curvature or coarser data (larger )ah2) wants a smaller ,k, and more noise wants a larger one. With h=1 the same numbers give ,k=3, and with h=161 they give :k=19: denser data allows more smoothing, which is the general rule that the optimal amount of regularisation falls, but does not vanish, as the dataset grows. The bias here is pure curvature, which is why k-NN is unbiased for linear f on a symmetric neighbourhood and why the symmetry assumption fails at the edge of the data.
Where this goes wrong
1. Preferring the unbiased estimator by reflex
Unbiased sounds like correct, and an estimator that is biased on purpose sounds like a trick.
,MSE(θ^)=bias2+Var, and xˉ has bias 0Right so far: Problems 1 and 2.
“Zero bias means the error is as small as it can be.”The habit that causes the mistake: zero bias sets one term of the sum to zero and says nothing about the other.
MSE(cxˉ)≥MSE(xˉ) for every c=1For ,μ=1,,σ2=1,,N=4,c=0.8 gives 0.2<0.25 (Problem 2); ridge at λ∗=σ2/w2 beats least squares for every w and s (Problem 6); and S/(N+1) beats the unbiased S/(N−1) for every N (Problem 9). What is true is that among unbiased estimators the one with the smallest variance is best, and that is a different and smaller competition. The reflex has a real basis, though: shrinkage needs to know which way to shrink and how far, and when nothing is known about θ the unbiased estimator is the one that cannot be fooled. Regularisation is exactly the act of putting that knowledge, usually “the true parameters are not huge”, into the estimator.
2. Applying the decomposition to the training error
The three-term formula is about expected squared error, and the error that is to hand is the one on the training set.
E[(y−f^D(x))2]=σ2+bias2+Var for a test point (x,y)Right so far: Problem 3.
“The training points are points too, so the same formula gives the expected training error.”The habit that causes the mistake: Problem 3's step 3 dropped the cross term because the test noise ε is independent of ;D; a training point's noise εn is part of .D.
E[(yn−f^D(xn))2]=σ2+bias(xn)2+Var(xn) for a training point xnThe cross term is ,−2E[εn(f^D(xn)−f(xn))], and for Problem 4's least squares, ,f^D(xn)−f(xn)=xn∑mxmεm/s, so it equals :−2xn2σ2/s<0: the fit leans towards its own noise. Averaged over the N training points the expected training error is ,σ2−σ2/N, below the noise floor that no test error can beat, and the check confirms σ2(N−1)/N exactly. The general version is σ2(N−p)/N for a p-parameter linear model, the reason the MLE page's σ^2 is biased low, and the reason training error underestimates test error by an amount that grows with the number of parameters.
3. Guessing the ridge variance by analogy
Least squares has variance ,σ2/s, ridge replaces s by s+λ everywhere else, and the variance is written the same way.
w^=∑nxnyn/s has Var(w^)=σ2/sRight so far: Problem 4.
“Ridge just replaces s by .s+λ.”The shortcut that causes the mistake: it does in the estimator, and the variance is not linear in the estimator's denominator.
Var(w^λ)=s+λσ2w^λ=∑nxnyn/(s+λ) is ∑nxnεn/(s+λ) plus a constant, with variance σ2s/(s+λ)2 (Problem 5): the numerator keeps the s because the noise enters through ,∑nxnεn, whose variance is σ2s regardless of .λ. The two agree only at ;λ=0; at Problem 6's λ∗=1 the wrong formula gives 0.2 where the variance is ,0.16, and it reports the total MSE at λ∗ as 0.24 rather than ,0.2, nearly erasing the gain over least squares. The matrix version has the same shape: ,Cov(w^λ)=σ2(X⊤X+λI)−1X⊤X(X⊤X+λI)−1, not ,σ2(X⊤X+λI)−1, the latter being the Bayesian posterior covariance, a different object that answers a different question.
4. Dropping the noise term
Bias and variance are the two things a model can change, and the decomposition is remembered as those two.
ED[(f(x)−f^D(x))2]=bias2+VarRight so far: Problem 3, step 4, for the error against the noiseless .f(x).
“Test error is bias squared plus variance.”The shortcut that causes the mistake: that is the error against ;f(x); the test error is measured against ,y=f(x)+ε, and the noise does not go away because it is not the model's fault.
A learner with zero bias and zero variance has expected test error 0It has expected test error ,σ2, the floor in Problem 3, and so does f^D=f itself. The practical damage is a target that cannot be hit: a model whose test error has stopped at σ2 is being pushed to fit noise, and the bias–variance accounting then charges every extra bit of fit to variance. A related reading error is to take Problem 3 as saying the test error is at least σ2 at every point; it is at least σ2 in expectation, and Mistake 2 shows the training error sitting below it because its noise is not independent of the fit.
5. Dividing the variance of correlated models by their number
Averaging B independent measurements divides the variance by ,B, and the B models in an ensemble are counted as if they were independent.
Var(fˉ)=B211⊤Σ1Right so far: Problem 8, step 2.
“Each model is its own fit, so the models are independent and .Σ=vI.”The habit that causes the mistake: models trained on resamples of the same data, with the same features and the same algorithm, make many of the same errors, and Σ has off-diagonal entries ρv with ρ typically well above zero.
,Var(fˉ)=Bv, so a large enough ensemble has negligible varianceIt is ρv+(1−ρ)v/B (Problem 8), which never falls below :ρv: with ,ρ=0.5, averaging 100 models leaves ,0.505v, almost the same as averaging 10 (),0.55v), and the 1/B line predicts .0.01v. The error compounds if the leftover variance is then blamed on bias and the members made more flexible, which raises v and often ρ too. The lever that works is :ρ: random forests subsample features at every split for exactly this reason, and the variance page's sample mean under common correlation is the same formula with the same floor.