The bias-variance tradeoff is a very important concept in machine learning, which represents the strain that a model has between its ability to cut back the errors on the training set (its ) versus its ability to generalize well to recent unseen examples (its ).

Usually, as we make our model more complex (e.g., by adding more nodes to a call tree), its bias decreases because the model adapts itself to the particular patterns and peculiarities of the training set (learning the training examples “by-heart”), and consequently the model loses its ability to generalize and supply good predictions on the test set (i.e., its variance increases).

## Formal Evaluation

The errors in a model’s predictions could be decomposed into three components:

- in the info itself. This noise could also be caused attributable to various reasons, equivalent to internal noise within the physical devices that generated our measurements, or errors made by humans that entered the info into our databases.
- The of the model, which represents the difference between the model’s predictions and the true labels of the info.
- The of the model, which represents how the model’s predictions vary across different training sets.

In the next sections we’re going to prove the next statement:

Typically, we cannot control the interior noise, but only the bias and the variance components of the prediction error. And because the prediction error of a given model is constant, trying to cut back its bias will increase its variance and vice versa (thereby we now have the ).

Before proving the above statement, we want a number of definitions and notations.

Assume that we now have a training set of *n* sample points, denoted by *D* = {(*x*₁, *y*₁), (*x*₂, *y*₂), … , (*xₙ, yₙ*)}, where *xᵢ* represents the features of point *i* (typically *xᵢ* is a vector) and *yᵢ* represents the true label of that time.

We assume that the labels are generated by some unknown function*y* = *f*(*x*) + *ϵ*, which our model is attempting to learn. *ϵ* represents the intrinsic noise of the info, and we assume that it’s uniformly distributed across all the info points with expected value of 0 (E[*ϵ*] = 0), and an ordinary deviation of *σ *(Var[*ϵ*] = *σ*²).

The function that our model learns from the given training set is known as the model’s and denoted by *h*(*x*).

Our goal is to seek out an hypothesis *h*(*x*) that’s as close as possible to the true function *f*(*x*), or in other words, we would love to reduce the mean squared error between *h*(*x*) and the true labels *y* across all of the possible data sets *D *that would have been used to coach the model:

The subscript *D* is used to point that the model was built based on a selected training set *D*.

A model with a great generalization ability should give similar predictions no matter the particular training set that was used to coach it, since that may mean that the model has learned the overall patterns in the info, moderately than adapting itself to the particular peculiarities of the training set that was used to coach it.

## Formal Proof

Using our definition of *y* = *f*(*x*) + *ϵ*, we will write:

By rearranging the terms and expanding the square brackets we get:

From the linearity of expectation we get:

The last term is the same as zero, because the expectation of the product of two variables is the product of the person expectations, and the expectation of the noise is 0 ((E[*ϵ*] = 0). Due to this fact, we will write:

Because the noise *ϵ *doesn’t depend upon the particular training set *D*, and its variance is the same as *σ*², we will write:

We now make use of the incontrovertible fact that Var(*X*) = E[*X*²] – E[*X*]² to jot down:

And by rearranging the terms we get:

Since *f*(*x*) doesn’t depend upon the particular training set *D*, it doesn’t affect the variance, thus we will write:

Substituting this expression back into the equation for the prediction error we get our outcome:

The primary term on the correct side of this equation represents the bias squared, since *E*[*f*(*x*)-*h*(*x*)] is the expected error between the model’s predictions and the true function. The second term represents the variance of the model, and the third term represents the noise.

Due to this fact, we now have shown that:

## Finding the Right Balance

The best model would minimize each the bias and the variance. Nevertheless, in practice we cannot achieve each of those objectives at the identical time.

When the model is simply too easy (e.g., using a linear regression to model a posh function), it ignores useful information in the info set, and due to this fact it is going to have a high bias. On this case, we are saying that the model is the info.

When the model is simply too complex (e.g., using a polynomial with a high degree to model an easy function), it adapts itself to the particular training set and due to this fact has a high variance. On this case, we are saying that the model is the info.

Due to this fact, we must always strive to seek out a model that lays within the sweet spot between overfitting and underfitting, i.e., a model that shouldn’t be too easy nor too complex.

There are numerous ways to seek out such models, depending on the particular machine learning algorithm that you simply are using. For instance, we will use regularization to manage the tradeoff between the bias and variance.

## Regularization

Regularization is a way to forestall overfitting by penalizing complex models. The concept is so as to add a penalty term to the price function of the model, such that it becomes depending on two aspects:

Cost(*h*) = Training Error(*h*) + *λ* Complexity(*h*)

*λ* is a hyperparameter that controls the tradeoff between the bias and the variance. Higher *λ *will induce a bigger penalty on the complexity of the model, and thus will result in simpler models with higher error on the training set but with smaller variance.

The complexity of the model could be measured in other ways. For instance, in linear regression the complexity is usually specified by the dimensions of the model’s parameters (weights).

You’ll find more details about regularization in this text of mine.