Unit 6, lesson 36

Bias, Variance, and Irreducible Error

How expected squared error at a fixed input splits into squared bias, prediction variance and irreducible error, what training randomness the average covers, and why the bias-variance tradeoff is a tendency.

  • Video 36
  • Bias, Variance and Cross-Validation

Collect several independent training sets from the same process, fit one regression procedure to each, and query every fitted model at the same input. The predictions disagree with one another, their average can sit away from the true mean outcome at that input, and the new outcome itself scatters around that mean. How much of the expected squared error does each of these three effects contribute? This lesson splits the expected squared error at a fixed input into squared bias, prediction variance and irreducible error, states exactly what the averages range over, and shows why the familiar tradeoff between bias and variance is a tendency to check rather than a law.

Key terms

Bias-variance decomposition

Definition Fix an input x\mathbf{x} and let YY be a new outcome at this input. Write Y=f(x)+εY = f(\mathbf{x}) + \varepsilon, where f(x)=E[Y∣X=x]f(\mathbf{x}) = E[Y \mid \mathbf{X} = \mathbf{x}] is the conditional mean, so the noise has E[ε∣X=x]=0E[\varepsilon \mid \mathbf{X} = \mathbf{x}] = 0, and assume its variance σ2(x)=Var⁡(ε∣X=x)\sigma^2(\mathbf{x}) = \operatorname{Var}(\varepsilon \mid \mathbf{X} = \mathbf{x}) is finite. A learning procedure trained on a random training set DD, possibly with further random choices during training, returns a predictor f^D\hat{f}_D. Assume that E[f^D(x)2]E[\hat{f}_D(\mathbf{x})^2] is finite and that the new outcome is independent of the training set and of every random choice made in training. The average fitted prediction is

m(x)=ED[f^D(x)],m(\mathbf{x}) = E_D\bigl[\hat{f}_D(\mathbf{x})\bigr],

where EDE_D averages over training sets and training randomness. At the fixed input abbreviate f=f(x)f = f(\mathbf{x}), m=m(x)m = m(\mathbf{x}), σ2=σ2(x)\sigma^2 = \sigma^2(\mathbf{x}) and f^=f^D(x)\hat{f} = \hat{f}_D(\mathbf{x}). Then the expected squared prediction error, averaged over the training randomness and the new outcome, is

E[(Y−f^)2]=(m−f)2+ED[(f^−m)2]+σ2,\begin{aligned} &E\bigl[(Y - \hat{f})^2\bigr] \\[0.4em] &\quad = (m - f)^2 \\[0.4em] &\qquad + E_D\bigl[(\hat{f} - m)^2\bigr] \\[0.4em] &\qquad + \sigma^2 , \end{aligned}

which is squared bias plus prediction variance plus irreducible error. To derive it, write the error as Y−f^=(f−m)+(m−f^)+εY - \hat{f} = (f - m) + (m - \hat{f}) + \varepsilon and square. The first part is a constant at this input, the second has expectation 00 by the definition of mm, and the noise has mean 00 and is independent of f^\hat{f}, so all three cross terms have expectation 00. If the input X\mathbf{X} of a new case is drawn independently of the training data, averaging the three terms over its distribution gives the integrated decomposition of the expected squared error, provided these expectations are finite. The identity belongs to squared loss. For class labels under zero-one loss, bias and variance are commonly defined through the most frequent prediction, and those terms do not add up to the error rate. Extra variability can even lower the error there. If P(Y=1∣x)=0.8P(Y = 1 \mid \mathbf{x}) = 0.8, a classifier that always predicts 00 errs with probability 0.80.8. One that predicts 11 for 4040 percent of training draws still predicts the wrong label 00 most often, yet it errs with probability 0.6⋅0.8+0.4⋅0.2=0.560.6 \cdot 0.8 + 0.4 \cdot 0.2 = 0.56.

In plain words A prediction can miss for three different reasons. The procedure can aim at the wrong value on average, its aim can wobble from one training set to the next, and the outcome can land away from its own mean. Under squared loss these three costs simply add, because each is measured around a different center and the mixed terms average out. The averages run over many possible training sets, so no single fitted model shows its own bias or variance.

Example The numbers in this lesson are constructed. At a fixed input the conditional mean is f=10f = 10, and a new outcome is 88 or 1212 with probability 1/21/2 each, so σ2=4\sigma^2 = 4. Learner A draws two independent training outcomes from the same process at this input and predicts their mean minus 11. The four equally likely ordered training pairs (8,8)(8, 8), (8,12)(8, 12), (12,8)(12, 8) and (12,12)(12, 12) give the predictions 77, 99, 99 and 1111. The average prediction is m=9m = 9, so the squared bias is (9−10)2=1(9 - 10)^2 = 1. The deviations from 99 are −2,0,0,2-2, 0, 0, 2, so the prediction variance is (4+0+0+4)/4=2(4 + 0 + 0 + 4)/4 = 2. The decomposition gives 1+2+4=71 + 2 + 4 = 7 squared units. A direct check pairs each of the four predictions with each of the two outcomes. The eight equally likely squared errors are 1,25,1,9,1,9,9,11, 25, 1, 9, 1, 9, 9, 1, and their average is 56/8=756/8 = 7.

Squared bias

Definition Under the setup of the decomposition, the bias of a learning procedure at the input x\mathbf{x} is

Bias⁡(x)=m(x)−f(x),\operatorname{Bias}(\mathbf{x}) = m(\mathbf{x}) - f(\mathbf{x}),

the average fitted prediction minus the conditional mean, and the squared bias is its square. A positive and a negative bias of the same size give the same squared bias. Bias belongs to the whole experiment, the procedure together with the data-generating process, the training-set size and the training randomness. It is not a property of one fitted model, which gives a single prediction at x\mathbf{x} and no average. It usually changes with the input, so a procedure can be unbiased at some inputs and biased at others, and the integrated squared bias averages it over the input distribution. Computing it requires ff, which is known in simulations and constructed examples but unknown for real data.

In plain words Bias asks where the procedure aims on average. Retrain it on endless fresh training sets, average its predictions at the input, and measure how far that average lands from the true mean outcome. A model too rigid to follow the true shape tends to miss in the same direction on every training set.

Example Learner A averages 99 against the conditional mean 1010, so its bias is −1-1 and its squared bias is 11. The bias comes entirely from subtracting 11. Learner B uses the same two training outcomes y1y_1 and y2y_2, in the order drawn, and predicts y1/2+y2−5y_1/2 + y_2 - 5. For the pairs (8,8)(8, 8), (8,12)(8, 12), (12,8)(12, 8) and (12,12)(12, 12) it predicts 4+8−5=74 + 8 - 5 = 7, 4+12−5=114 + 12 - 5 = 11, 6+8−5=96 + 8 - 5 = 9 and 6+12−5=136 + 12 - 5 = 13. These average to 1010, so learner B is unbiased at this input. So is the plain mean of the two training outcomes, whose predictions are 88, 1010, 1010 and 1212.

Prediction variance

Definition With the abbreviations of the decomposition, the prediction variance of a procedure at the input x\mathbf{x} is

Var⁡D(f^)=ED[(f^−m)2],\operatorname{Var}_D(\hat{f}) = E_D\bigl[(\hat{f} - m)^2\bigr],

the expected squared distance of a fitted prediction from the average fitted prediction, with the expectation over the training set and all training randomness. It is the variance of a fully specified probability experiment, so when finitely many equally likely predictions are possible, the average of their squared deviations divides by their number and not by one less. It measures how sensitive the fitted prediction is to the particular training sample and to random choices in training. It contains no noise from the new outcome. It equals 00 exactly when the prediction at x\mathbf{x} is the same for every training draw, apart from events of probability 00.

In plain words Variance asks how much the prediction at this input would move if a different training set had been collected or training had been rerun with another seed. A procedure that follows the details of its sample closely gives scattered predictions, even when they are right on average.

Example Learner A’s deviations −2,0,0,2-2, 0, 0, 2 from its average give the variance 22. Learner B’s predictions 7,11,9,137, 11, 9, 13 deviate from 1010 by −3,1,−1,3-3, 1, -1, 3, so its variance is (9+1+1+9)/4=5(9 + 1 + 1 + 9)/4 = 5. The difference comes from the weights on the two independent training outcomes, each of variance 44. Learner B weights them by 1/21/2 and 11, whose squares add to 5/45/4, and learner A by 1/21/2 and 1/21/2, whose squares add to 1/21/2. The variances are 4⋅5/4=54 \cdot 5/4 = 5 and 4⋅1/2=24 \cdot 1/2 = 2, and the subtracted constants play no part.

Irreducible error

Definition The irreducible error at the input x\mathbf{x} is the conditional variance of the outcome. With the two expectations below taken conditionally on X=x\mathbf{X} = \mathbf{x}, it is

σ2(x)=E[(Y−f(x))2].\sigma^2(\mathbf{x}) = E\bigl[(Y - f(\mathbf{x}))^2\bigr].

For every number aa, the expected squared error of the constant prediction aa at this input is

E[(Y−a)2]=σ2(x)+(f(x)−a)2,\begin{aligned} &E\bigl[(Y - a)^2\bigr] \\[0.4em] &\quad = \sigma^2(\mathbf{x}) + \bigl(f(\mathbf{x}) - a\bigr)^2 , \end{aligned}

and only a=f(x)a = f(\mathbf{x}) reaches σ2(x)\sigma^2(\mathbf{x}). The same holds for a random prediction, such as a fitted model’s, that is independent of the new outcome. Its expected squared error at this input is σ2(x)\sigma^2(\mathbf{x}) plus the expected squared distance of the prediction from f(x)f(\mathbf{x}), so no such prediction gets below σ2(x)\sigma^2(\mathbf{x}). The floor is irreducible relative to the information in x\mathbf{x} and to squared loss. It does not depend on the learning procedure, so procedures compared at the same input under the same outcome process differ only in squared bias plus variance. A further feature ZZ known at prediction time changes the conditional distribution, and by the law of total variance E[Var⁡(Y∣X,Z)∣X=x]≤σ2(x)E\bigl[\operatorname{Var}(Y \mid \mathbf{X}, Z) \mid \mathbf{X} = \mathbf{x}\bigr] \le \sigma^2(\mathbf{x}), so new information can lower the floor on average and can never raise it on average.

In plain words Even the true conditional mean misses individual outcomes, because cases with the same input still differ. That spread is the floor for squared error with this information. More training data or a better algorithm cannot push below it, but a new measurement that is available at the time of prediction can.

Example With outcomes 88 or 1212 and conditional mean 1010, even the perfect prediction 1010 has squared error 44 on every outcome, so σ2=4\sigma^2 = 4, and this accounts for 44 of learner A’s 77 squared units. A constant prediction of 99 would score 4+1=54 + 1 = 5. If a second feature known at prediction time revealed which of the two outcomes is coming, the conditional variance given both features would be 00. With the original input alone, no predictor gets below 44.

Bias-variance tradeoff

Definition The bias-variance tradeoff is the frequently observed tendency, within a family of models indexed by a complexity setting, for more flexible settings to lower squared bias and raise prediction variance, and for restrictions such as a larger ridge penalty, fewer features or more neighbors in nearest-neighbor regression to do the opposite, so that expected squared error is often smallest at an intermediate setting. It is a tendency and not a theorem. Neither term has to move monotonically with the number of parameters or any other complexity count, and the error curve need not be U-shaped. The amount of data, the optimization method, the architecture, the regularization and the training randomness all change both terms. One procedure can have both smaller bias and smaller variance than another, so lowering the error does not always require giving up one term for the other. The decomposition behind the picture is the squared-loss identity under the conditions stated above.

In plain words A rigid model tends to miss in the same way on every training set, and a flexible one tends to chase the quirks of each set. That picture suggests which direction to adjust a model, but whether a given change helps has to be checked with honest validation, not assumed.

Example At the constructed input, learner A has expected squared error 1+2+4=71 + 2 + 4 = 7 and learner B has 0+5+4=90 + 5 + 4 = 9. Removing the bias made learner B worse, because its variance rose by 33 while its squared bias fell by only 11. The plain mean of the two training outcomes has squared bias 00, variance 22 and expected squared error 0+2+4=60 + 2 + 4 = 6, below both. It has the bias of learner B and the variance of learner A at the same time, so in this comparison nothing had to be traded.

Training randomness

Definition Training randomness is every source of chance that makes the fitted predictor random. It includes the draw of the training set DD itself and random choices inside training, such as initial weights, the order of mini-batches, random subsamples of rows or features and random fold assignments inside a tuning search. The expectation EDE_D in the decomposition averages over all the sources that are allowed to vary, so a statement of bias or variance has to say which sources were varied and which were held fixed, for example by recording a seed. A single trained model on a single data set is one draw from this experiment, and it reveals neither m(x)m(\mathbf{x}) nor the variance. Estimating them needs repeated training on fresh samples from a process whose ff is known, as in a simulation, or further assumptions. Rerunning training with new seeds on one fixed data set measures only the part of the variance that the seeds cause.

In plain words A fitted model is the outcome of a random experiment, and a new sample or a new seed would have produced a different one. Bias and variance describe that experiment as a whole, which is why one trained model cannot report its own bias and variance.

Example Give learner A an extra random step, standing in for a random initialization that leaves a trace in the final model. After averaging its two training outcomes and subtracting 11, it adds 11 or −1-1 with probability 1/21/2 each, independently of the data and of the new outcome. The average prediction stays 99, the variance becomes 2+1=32 + 1 = 3, and the expected squared error becomes 1+3+4=81 + 3 + 4 = 8. Averaging the predictions of rr independently seeded runs on the same training set cuts the seed part of the variance to 1/r1/r and leaves the sample part 22, for an expected squared error of 7+1/r7 + 1/r. Rerunning on one training set with new seeds would expose only the seed part, never the sample part.

Check yourself

  1. At the constructed input with conditional mean 1010 and new outcomes 88 or 1212 with probability 1/21/2 each, learner C produces the predictions 88, 1010 and 1212 with probability 1/31/3 each, independently of the new outcome. Find its bias, prediction variance and expected squared error, check the result directly, and compare learner C with learner A.
Show the answer

The average prediction is (8+10+12)/3=10(8 + 10 + 12)/3 = 10, so the bias and the squared bias are 00. The deviations from 1010 are −2,0,2-2, 0, 2, so the prediction variance is (4+0+4)/3=8/3(4 + 0 + 4)/3 = 8/3. Adding the irreducible error 44 gives

0+83+4=203≈6.670 + \frac{8}{3} + 4 = \frac{20}{3} \approx 6.67

squared units.

For the direct check, pair each prediction with each outcome. The six equally likely squared errors are 00 and 1616 for the prediction 88, 44 and 44 for 1010, and 1616 and 00 for 1212. They add to 4040, and 40/6=20/340/6 = 20/3.

Learner C beats learner A’s 77 although its variance 8/38/3 is larger than A’s 22, because it has no squared bias where A has 11. The comparison holds for this input, this outcome process and squared loss, not for every input or every cost of error.

  1. A team fits one model and finds a training MSE of 2.02.0 and a validation MSE of 5.05.0. A colleague reports that the model’s squared bias is 2.02.0 and its variance is 3.03.0. What is wrong with this reading, and what would it take to estimate squared bias and variance?
Show the answer

Squared bias and variance describe the distribution of fitted predictions over repeated training sets and training randomness, measured against the true conditional mean. One fitted model gives one prediction at each input, so neither quantity can be read from it. For this fixed fitted model f^\hat{f} and a new outcome independent of its training data, the expected squared error at an input is

(f^(x)−f(x))2+σ2(x),\bigl(\hat{f}(\mathbf{x}) - f(\mathbf{x})\bigr)^2 + \sigma^2(\mathbf{x}),

with no variance term at all, and the validation MSE estimates the average of this over the validation inputs, irreducible error included.

The training MSE is not a squared bias either. It is computed on the cases that shaped the model, so it tends to understate the error on new cases, and it also reflects the noise in the training outcomes, part of which the model has fitted. The gap of 3.03.0 therefore mixes the optimism of training error with sampling noise in both numbers, and it is not the variance.

Estimating the components needs repeated training on independent samples from a process with known ff, as in a simulation, or strong extra assumptions. With real data, the honest diagnostics are comparisons of training and validation behavior, repeated splits and learning curves, described in those terms and not as measured bias and variance.

  1. Constructed training data have one outcome at each of the fixed inputs 0,1,2,3,40, 1, 2, 3, 4. The outcome at input xx is x+εx + \varepsilon, so the conditional mean is f(x)=xf(x) = x, and the noise terms are independent with mean 00 and variance 44. A new outcome at x=0x = 0 follows the same model, independently of the training data. Nearest-neighbor regression predicts at x=0x = 0 the average of the training outcomes at the kk nearest inputs. Find the squared bias, the variance and the expected squared error for k=1,2,3k = 1, 2, 3, and say which kk is best. Which kk would be best if the conditional mean were constant instead?
Show the answer

The distances from 00 to the training inputs are 0,1,2,3,40, 1, 2, 3, 4, so there are no ties, and the kk nearest inputs are 0,1,…,k−10, 1, \dots, k - 1. The inputs are fixed, so the only training randomness is the noise in the training outcomes. The average prediction is the mean of ff over those inputs, (k−1)/2(k - 1)/2, and f(0)=0f(0) = 0, so the squared bias is (k−1)2/4(k - 1)^2/4. The prediction averages kk independent outcomes of variance 44, so its variance is 4/k4/k. The expected squared error is

(k−1)24+4k+4.\frac{(k - 1)^2}{4} + \frac{4}{k} + 4 .

For k=1k = 1 it is 0+4+4=80 + 4 + 4 = 8. For k=2k = 2 it is 0.25+2+4=6.250.25 + 2 + 4 = 6.25. For k=3k = 3 it is 1+4/3+4=19/3≈6.331 + 4/3 + 4 = 19/3 \approx 6.33. So k=2k = 2 is best of the three, and k=4k = 4 and k=5k = 5 give 7.257.25 and 8.88.8. Here squared bias rises with kk and variance falls, and the error dips and then rises.

If the conditional mean were constant, every neighbor would have the same mean, so the bias would be 00 for every kk and the error 4/k+44/k + 4 would fall all the way to 4.84.8 at k=5k = 5. Averaging more neighbors would then cost nothing. Whether more flexibility pays depends on the shape of ff and the size of the noise, which is why the tradeoff is a tendency to check and not a rule.

How this lesson connects