Although the concept of bias-variance trade-off is often discussed in machine learning textbooks, e.g., Bishop (2006), Hastie, Tibshirani, and Friedman (2009), James et al. (2013), I also find it important in almost any occasions in which we need to fit a statistical model on a data set with a limited number of observations. To better understand the trade-off, we should be clear about the bias-variance decomposition. I prefer to call it bias-variance breakdown cause there are fewer syllables. This post is an attempt to go through the breakdown in a very detailed manner, mainly for my future reference. It may not be 100% correct because I’m very new to this topic. I will make changes if there is anything wrong.

## What is being broken down?

First off, the bias-variance concept lives in theory. In practice, we have no way to separate bias and variance. What we could observe is just the sum of them, as well as something called “irreducible error”. We will cover that later in this post.

Since we are talking about theory, let’s make up the thing that needs to be broken down. Let’s assume that we are interested in studying the relationship between $X$ and $Y$. Suppose the relationship is a regression model $Y = f(X) + \epsilon$, $\epsilon$ is i.i.d. $E(\epsilon) = 0$ and $\text{Var}(\epsilon) = \sigma^2$.

Then we obtain a data set, $D$, that has $x_i$ and $y_i$ ($D = {x_i, y_i}$). Note that in the data set, $X$ and $Y$ are lowercase and have subscripts. This is because we are referring to observed data of $X$ and $Y$.

As usual, we fit a model to $D$ and obtain the model $\hat{f}(x_i)$. There is a “hat” on $f(x_i)$ because we are estimating the true model, $f()$. After getting $\hat{f}()$, we are interested in how this model would perform in the future. So we have to come up with a way to measure the performance of the model when applied to new data. The most common way to measure the predictive performance of a model is mean squared error (MSE) on a new data set ${x^*, y^*}$, or theoretically, the expected squared error:

This is the thing to be broken down.

## Breaking it down

Before we go further, we need to make sure we are clear about which is which. Since this is an expected value, there must be random variables in this equation. What is random here? First, let’s take a look at $\hat{f}(x^*)$. We know that $\hat{f}()$ comes from $D$, and $D$ contains $\epsilon$, because the true model we assumed is $Y = f(X) + \epsilon$. So $\hat{f}()$ also contains $\epsilon$ and hence it is a random variable. Second, what about $y^*$? Since ${x^*, y^*}$ is a sample from the true model, it again contains $\epsilon$, therefore $y^*$ is also a random variable.

Let’s now play a mathematical trick:

\[E[(y^* - \hat{f}(x^*))^2] = E[(y^* - f(x^*) + f(x^*) - \hat{f}(x^*))^2]\]Here we just add and subtract $f(x^*)$, nothing is changed. Let $A = y^* - f(x^*)$ and $B = f(x^*) - \hat{f}(x^*)$. Then the above equation becomes:

Let’s put $A$ and $B$ back

\[E[(y^* - f(x^*))^2] + E[(f(x^*) - \hat{f}(x^*))^2] + 2E\{[y^* - f(x^*)][f(x^*) - \hat{f}(x^*)]\}\]This is very complicated, especially the long thing on the right. Let’s first expand it: \(2\{E[y^* f(x^*)] - E[y^* \hat{f}(x^*)] - E[f(x^*) f(x^*)] + E[f(x^*) \hat{f}(x^*)]\}\)

According to our theoretical model, we know that $y^* = f(x^*) + \epsilon$, so

\[2\{E[(f(x^*) + \epsilon) f(x^*)] - E[(f(x^*) + \epsilon) \hat{f}(x^*)] - E[f(x^*) f(x^*)] + E[f(x^*) \hat{f}(x^*)]\}\] \[2\{[f(x^*)]^2 - E[f(x^*) \hat{f}(x^*) + \epsilon \hat{f}(x^*)] - [f(x^*)]^2 + E[f(x^*) \hat{f}(x^*)]\}\] \[2\{[f(x^*)]^2 - E[f(x^*) \hat{f}(x^*)] + E[\epsilon \hat{f}(x^*)] - [f(x^*)]^2 + E[f(x^*) \hat{f}(x^*)]\}\]Four terms cancel out, the term $E[\epsilon \hat{f}(x^*)] = 0$, because $\epsilon$ and $\hat{f}(x^*)$ are independent. Therefore $E[\epsilon \hat{f}(x^*)] = E[\epsilon] \times E[\hat{f}(x^*)] = 0$.

OK. That long thing becomes zero and we are left with

\[E[(y^* - f(x^*))^2] + E[(f(x^*) - \hat{f}(x^*))^2]\]Now let’s play a similar trick on the second term, the first term remains unchanged.

\[E[(y^* - f(x^*))^2] + E\{[f(x^*) - E[\hat{f}(x^*)] + E[\hat{f}(x^*)] - \hat{f}(x^*)]^2\}\]Again let $A = f(x^*) - E[\hat{f}(x^*)]$ and $B = E[\hat{f}(x^*)] - \hat{f}(x^*)$.

Plug in $A$ and $B$.

\(E[(y^* - f(x^*))^2] + E\{[f(x^*) - E[\hat{f}(x^*)]]^2\} + E\{[E[\hat{f}(x^*)] - \hat{f}(x^*)]^2\}\) \(+ 2E\{[f(x^*) - E[\hat{f}(x^*)]][E[\hat{f}(x^*)] - \hat{f}(x^*)]\}\)

Let’s again look at the most annoying thing on the second row. We notice that (1) $f(x^*) - E[\hat{f}(x^*)]$ is a constant, and (2) the expected value of $E[\hat{f}(x^*)] - \hat{f}(x^*)]$ is just $E{E[\hat{f}(x^*)]} - E[\hat{f}(x^*)]$. This equals $E[\hat{f}(x^*)] - E[\hat{f}(x^*)] = 0$.

So we are left with

\[E[(y^* - f(x^*))^2] + E\{[f(x^*) - E[\hat{f}(x^*)]]^2\} + E\{[E[\hat{f}(x^*)] - \hat{f}(x^*)]^2\}\]We also notice that, in the second term, both $f(x^*)$ and $E[\hat{f}(x^*)]$ are constants, so we can drop the expectation operator.

Cool! We have finished the breakdown.

## Naming things

As a final step, let’s name the three terms in

\[E[(y^* - f(x^*))^2] + [f(x^*) - E[\hat{f}(x^*)]]^2 + E\{[E[\hat{f}(x^*)] - \hat{f}(x^*)]^2\}\]The first term, $E[(y^* - f(x^*))^2]$, is the variance of $\epsilon$, which is $\sigma^2$. We call this “irreducible error” or “irreducible noise”.

The second term, $[f(x^*) - E[\hat{f}(x^*)]]^2$, is the “squared bias”, because the definition of the bias of an estimator is $\text{bias}(\hat{\theta}) = E(\hat{\theta}) - \theta$.

The third term, $E{[E[\hat{f}(x^*)] - \hat{f}(x^*)]^2}$is, by definition, the variance of $\hat{f}(x^*)$.

So to put everything together,

\[E[(y^* - \hat{f}(x^*))^2] = \text{Var}(\epsilon) + \text{bias}^2(\hat{f}(x^*)) + \text{Var}(\hat{f}(x^*))\]## Reference

Bishop, Christopher M. (2006). *Pattern recognition and machine learning*. New York: Springer,

Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani. (2013). *An introduction to statistical learning: with applications in R*. New York :Springer,

Hastie, T., Tibshirani, R., & Friedman, J. H. (2009). *The elements of statistical learning: data mining, inference, and prediction*. 2nd ed. New York: Springer.