The Bias-Variance Decomposition Demystified
This post provides an intuitive explanation of the bias-variance decomposition. The bias-variance decomposition shows the generalisation error of a learning algorithm as the sum of three terms - bias, variance, and the irreducible error.

Introduction
The generalisation error of a machine learning algorithm measures how accurately the learning algorithm is able to predict the outcome of new data, unseen during training. The bias-variance decomposition shows the generalisation error as the sum of three terms: bias, variance, and the irreducible error.
In many statistics and machine learning texts, this decomposition is just presented and its derivation skipped. In texts where it derived, it is often presented in a way that is inaccessible to many people. And why is it important to understand this derivation? Because the decomposition is a useful theoretical tool for understanding the performance of a learning algorithm. Understanding how bias and variance contribute to generalisation error helps us understand underfitting and overfitting.
The goal of this article is to present the bias-variance decomposition in an accessible and easy-to-follow format. We will restrict our discussion of this decomposition to regression problems where mean squared error is used as the performance metric.
A Quick Statistics Refresher
We will go over some statistics concepts that will aid our understanding of the other concepts we will discuss.
Expectation of a random variable
The expectation1 or expected value of a random variable , written as , is the mean of a large number of observations of the random variable. The expectation has some basic properties:
- The expectation of any constant is the constant:
because the expection of a random variable is a constant.
- Linearity of expectations: For any random variables and , the expectation of their sum is equal to the sum of their expectations:
- For any random variable and a constant :
Variance of a random variable
The variance of a random variable is the expectation of the squared difference of the random variable from its expectation . In other words, it measures on average how spread out observations of the random variable are from the expectation of the random variable.
If we recall that the expectation of a random variable is a constant and if we use the properties stated in equations (3) and (4), we get:
We could rewrite equation (6) as:
Bias-Variance Decomposition for regression problems
If we are trying to predict a quantitative variable with features , we may assume that there is a true, unknown function that defines the relationship between and . Linear regression makes the following assumptions about this relationship:
- There is a linear function between the conditional population mean of the outcome and the features . This function is called the true regression line and it is the unknown function we will estimate using training data.
- Individual observations of will deviate from the true regression line by a certain amount. For example, if the feature is age of a person and the outcome variable is height, is the mean height of people of a certain age, and each person’s height will deviate from the mean height by a certain amount. An error term captures this deviation. We assume that it is normally distributed with expectation and variance . We also assume that is independent of and cannot be estimated from data.
To estimate the true, unknown function, we obtain a training dataset of examples drawn i.i.d2 from a data generating distribution and use a learning algorithm , say linear regression, to train a model that minimises mean squared error over the training examples. has subscript to indicate that the model was trained on a specific training dataset . We call the model of our true, unknown function .
What we really care about is how our model performs on previously unseen test data. For an arbitrary new point drawn from , we can use squared error to measure the model’s performance on this new example, where is the model’s prediction.
Now, because we draw our training set from a data generating distribution, it is possible, in principle3, to randomly draw a large number of different training datasets of examples from the distribution. If we use the learning algorithm to train a model on each training set, we will get different models that will give us different predictions on our arbitrary new point . We could calculate the squared error for each of the models predictions on .
To get an idea of how well, on average, the learning algorithm generalises to the previously unseen data point, we compute the mean/expectation of the squared errors of the models. This is called the expected squared error.
It is this expected squared error of the model that we will decompose into the bias, variance, and irreducible error components.

Expectation, Bias, and Variance of model
- Expectation of model
The expectation of the model is the average of the collection of models estimated over many training datasets. - Bias of model
The model bias describes how much the expectation of the model deviates from the true value of the function we are trying to estimate. Low bias signifies that our model does a good job of approximating our function, and high bias signifies otherwise. The bias measures the average accuracy of the model. - Variance of model
The model variance is the expectation of the squared differences between a particular model and the expectation of the collection of models estimated over many datasets. It captures how much the model fits vary across different datasets, so it measures the average consistency of the model. A learning algorithm with high variance indicates that the models vary a lot across datasets, while low variance indicates that models are quite similar across datasets.
Simulation 1
In practice, the true function we try to estimate is unknown, but for the sake of demonstration, we will assume that the true function is . Individual observations of will be . We assume that and . We will sample 50 data sets each with 100 individual observations, and on them we will fit three polynomial functions of varying degrees/complexities (1, 5, 20) to estimate our true function . Degree 1 is the least complex and degree 20 is the most complex.

We see from the image above that on average, the degree-1 polynomial model does a bad job of estimating our true function. It has a high bias. The variance is low, which means that the model is consistent across datasets. The degree-20 polynomial model has low bias, which means it does a good job of approximating our true function, but it has a high variance. This means that the model isn’t consistent across datasets. The degree-5 polynomial model has low bias (good estimate of our true function), and a relatively low variance (consistent across datasets).
The code for this simulation can be found here.
A Note on Bias-Variance Tradeoff
Bias-variance tradeoff is the tradeoff in attempting to simultaneously minimise the two sources of error that affect a model’s ability to generalise beyond its training set. Reducing bias generally increases variance and vice versa, and this is a function of a model’s complexity and flexibility. Low variance, high bias models tend to be less complex and less flexible and they mostly underfit the training data, while low bias, high variance models tend to be more complex with a flexible structure that tend to overfit. The optimal model will have both low bias and low variance.

Decomposing Expected Squared Error
As mentioned earlier, it is the expected squared error term in equation (11) that we will decompose into the bias, variance, and irreducible error components. To avoid clutter while decomposing, we will drop the sign from and from .
Equation (12) has three terms that we will deal with separately. If we consider the third term first, we know that is the expectation of our model. If we recall equations (2) and (9) and that , we can rewrite as:
For the first and second terms, we use equations (7), (9), and (13) to rewrite them as:
Substituting equations (13) and (14) into equation (12), we get:
If we rearrange equation (15) and use expansion of squares , we get:
And there is the error decomposed into its three constituent parts. To see a breakdown of how the third term became , you can check the footnote.4
Illustrating Bias-Variance Decomposition using simulated data
In Simulation 1, we estimated our true function by fitting three polynomial functions of varying complexities. What we really care about though is how our models perform on previously unseen data. In this section, we will demonstrate this and show how the expected squared error decomposes into the sum of variance and squared bias by running the following steps:
- Generate 100 random datasets of 500 observations each from . We assume that the .
- Split the generated datasets into training and test sets.
- Fit 20 polynomial functions (degrees from 1 to 20) on each of the training sets.
- Predict the value of the test set using the fitted models.
- Calculate the expected prediction error (the mean squared error) on the test set for each model.
- Show the expected prediction error as a sum of the variance and squared bias.
Simulation 2

We see from graph on the left in the image above that the error starts quite high, drops off to its minimum at model complexity 3, and then starts climbing rapidly as the complexity increases. If we look at the right graph, we see that it follows the bias-variance tradeoff. The squared-bias of the models drops as the complexity increases, but variance increases. Low bias, high variance models suggest that the models overfit the training data and hence performs poorly on the test data. Our optimal model has low bias and low variance and it is the model with complexity 3 in our simulation.

We see from the table above that the mean squared error (MSE) is a sum of the squared bias and the variance, as shown in equation (16). The irreducible part of the decomposition is not added to our sum because we cannot estimate it from data.
The code for this simulation can be found here.
Conclusion
We have shown the decomposition of the generalisation error for regression problems. It is possible to show this decomposition for classification problems. Pedro Domingos’ brilliant paper, A Unified Bias-Variance Decomposition and its Application goes over it in details.