These are my notes that cover the mathematical foundations of Linear Regression, taken while attending CSCI-UA 9473 - Foundations of Machine Learning at NYU Paris. They make use of probability theory, statistics, calculus, optimization, and linear algebra to formalize the concept of linear regression.

## Introduction

Linear regression is one of the most widely used statistical techniques in data analysis and machine learning. It provides a simple and intuitive linear model for modeling the relationship between a response variable and a set of explanatory variables.

## Least Squares Criterion

$$$J_{\tiny N}(\mathbf{w}) = \frac{1}{2N} \sum_{i=1}^N \left( y_i - w_1x_i - w_0 \right)^2$$$

where $\mathbf{w} = \begin{pmatrix} w_0 \\ w_1 \end{pmatrix}$. We want to find $\mathbf{w}$ such that $J_{\tiny N}(\mathbf{w})$ is minimized.

Therefore, lets compute $\nabla J_{\tiny N}(\mathbf{w})$:

$$$\nabla J_{\tiny N}(\mathbf{w}) = \left[\begin{array}{c} \dfrac{\partial J_{\tiny N}}{\partial w_0}(\left.\mathbf{w}\right)\\ \\ \dfrac{\partial J_{\tiny N}}{\partial w_1}(\left.\mathbf{w}\right)\\ \end{array}\right]$$$

where:

\begin{align} \dfrac{\partial J_{\tiny N}}{\partial w_0}(\left.\mathbf{w}\right) &= -\frac{1}{N} \sum_{i=1}^N \left( y_i - w_1x_i - w_0 \right)\\ \dfrac{\partial J_{\tiny N}}{\partial w_1}(\left.\mathbf{w}\right) &= -\frac{1}{N} \sum_{i=1}^N \left( y_i - w_1x_i - w_0 \right)x_i \end{align}

Setting them equal to zero, we get the critical values $(w_0, w_1)$ that minimize $J_{\tiny N}(\mathbf{w})$:

$\begin{equation*} \dfrac{\partial J_{\tiny N}}{\partial w_0}(\left.\mathbf{w}\right) = 0 \end{equation*}$
\begin{align*} &\implies \sum_{i=1}^N \left( y_i - w_1x_i - w_0 \right) = 0\\ &\implies w_0 = \frac{1}{N} \sum_{i=1}^N \left( y_i - w_1x_i \right)\\ &\implies w_0 = \left(\frac{1}{N} \sum_{i=1}^N y_i \right) - w_1 \left(\frac{1}{N} \sum_{i=1}^N x_i\right)\\ \end{align*}
$$$\therefore w_0 = \overline{y} - w_1 \overline{x}$$$

Similarly:

$\begin{equation*} \dfrac{\partial J_{\tiny N}}{\partial w_1}(\left.\mathbf{w}\right) = 0 \end{equation*}$
\begin{align*} &\implies \sum_{i=1}^N \left( y_i - w_1x_i - w_0 \right)x_i = 0\\ \end{align*}

Replacing the value of $w_0$, we get:

\begin{align} &\implies \sum_{i=1}^N \left( y_i - w_1x_i - \left(\overline{y} - w_1 \overline{x}\right) \right)x_i = 0\\ &\implies \sum_{i=1}^N \left( y_i - \overline{y} \right)x_i - w_1 \sum_{i=1}^N \left( x_i - \overline{x} \right)x_i = 0\\ &\implies w_1 = \frac{\displaystyle\sum_{i=1}^N \left( y_i - \overline{y} \right)x_i}{\displaystyle\sum_{i=1}^N \left( x_i - \overline{x} \right)x_i}\\ \end{align}

However, it is commonly written in terms of Pearson's sample correlation coefficient $r_{xy}$.

For that, a slight modification is required in equation $(6)$:

\begin{align} &\implies \sum_{i=1}^N \left( y_i - w_1x_i - \left(\overline{y} - w_1 \overline{x}\right) \right) \textcolor{#01B636}{(}x_i \textcolor{#01B636}{- \overline{x}) + \sum_{i=1}^N \left( y_i - w_1x_i - \left(\overline{y} - w_1 \overline{x}\right) \right) \overline{x}}= 0\\ \end{align}

Even though we have added the part in green, we can show that the second term is zero as:

\begin{align*} \sum_{i=1}^N \left( y_i - w_1x_i - \left(\overline{y} - w_1 \overline{x}\right) \right) = \textcolor{#ca0047}{\sum_{i=1}^N y_i} \textcolor{#8047cd}{- w_1 \sum_{i=1}^N x_i} \textcolor{#ca0047}{- N \overline{y}} \textcolor{#8047cd}{+ N w_1 \overline{x}} = 0 \end{align*}

Therefore, from equation $(9)$, we get:

$\begin{equation*} \implies \sum_{i=1}^N \left( y_i - w_1x_i - \left(\overline{y} - w_1 \overline{x}\right) \right) \left(x_i - \overline{x}\right) = 0 \end{equation*}$
\begin{align} \therefore w_1 = \frac{\displaystyle\sum_{i=1}^N \left( y_i - \overline{y} \right) \left(x_i - \overline{x}\right)}{\displaystyle\sum_{i=1}^N \left( x_i - \overline{x} \right)^2} = r_{xy} \cdot \frac{\sigma_y}{\sigma_x} \end{align}

Here, $\sigma_y$ and $\sigma_x$ are standard deviations of $x$ and $y$.

$r_{xy}$ is the Pearson's sample correlation coefficient between $x$ and $y$ defined as:

$$$r_{xy} = \frac{\displaystyle\sum_{i=1}^N \left( y_i - \overline{y} \right) \left(x_i - \overline{x}\right)}{\displaystyle\sqrt{\sum_{i=1}^N \left( y_i - \overline{y} \right)^2} \displaystyle\sqrt{\sum_{i=1}^N \left( x_i - \overline{x} \right)^2}}$$$

## Multiple Linear Regression

In multiple linear regression, there are multiple independent variables in the equation rather than just one. The mathematics behind multiple linear regression involves using matrix operations to solve for the coefficients of the regression equation.

The regression equation is now represented as:

$$$y = w_0 + w_1x_1 + w_2x_2 + \cdots + w_dx_d$$$

where $x_1, x_2, \cdots, x_d$ are the independent variables and $w_0, w_1, \cdots, w_d$ are the coefficients of the equation.

We define $\mathbf{w} = \begin{pmatrix} w_0 \\ w_1 \\ \vdots \\ w_d \end{pmatrix}$ and augment each data point as $\mathbf{x} = \begin{pmatrix} 1 \\ x_1 \\ \vdots \\ x_d \end{pmatrix}$, so that the equation can be written as:

$$$y = \langle \mathbf{w}, \mathbf{x} \rangle = \mathbf{w}^T \mathbf{x}$$$

## Least Squares Criterion

$$$J_{\tiny N}(\mathbf{w}) = \frac{1}{2N} \| \mathbf{y} - \Phi \mathbf{w}\|^2$$$

where:

$\mathbf{y} = \begin{pmatrix} y_1 \\ y_2 \\ \vdots \\ y_{\tiny N} \end{pmatrix}$ is the vector of target values.

$\Phi \mathbf{w} = \begin{pmatrix} \langle \mathbf{x_1}, \mathbf{w} \rangle \\ \langle \mathbf{x_2}, \mathbf{w} \rangle \\ \vdots \\ \langle \mathbf{x_{\tiny N}}, \mathbf{w} \rangle \end{pmatrix} = \begin{pmatrix} \mathbf{x_1}^T \mathbf{w} \\ \mathbf{x_2}^T \mathbf{w} \\ \vdots \\ \mathbf{x_{\tiny N}}^T \mathbf{w} \end{pmatrix} = \begin{pmatrix} \mathbf{x_1}^T \\ \mathbf{x_2}^T \\ \vdots \\ \mathbf{x_{\tiny N}}^T \end{pmatrix}\mathbf{w}$ is the vector of predictions.

$\Phi = \begin{pmatrix} \mathbf{x_1}^T \\ \mathbf{x_2}^T \\ \vdots \\ \mathbf{x_{\tiny N}}^T \end{pmatrix} = \begin{pmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1d} \\ 1 & x_{21} & x_{22} & \cdots & x_{2d} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & x_{\tiny{N}1} & x_{\tiny{N}2} & \cdots & x_{\tiny{N}d} \end{pmatrix}$ is called the design matrix. It is of size $N \times (d+1)$.

$\mathbf{w} = \begin{pmatrix} w_0 \\ w_1 \\ \vdots \\ w_d \end{pmatrix}$ is the vector of weights.

We want to find the minimizer for $J_{\tiny N}(\mathbf{w})$, so we solve:

$\begin{equation*} \nabla J_{\tiny N}(\mathbf{w}) = 0 \end{equation*}$
\begin{align*} \implies &\nabla_{\mathbf{w}} \begin{pmatrix} \| \mathbf{y} - \Phi \mathbf{w}\|^2 \end{pmatrix} = 0\\ \implies &-2\Phi^T \left( \mathbf{y} - \Phi \mathbf{w} \right) = 0\\ \implies &\Phi^T \mathbf{y} = \Phi^T \Phi \mathbf{w} \end{align*}
$$$\therefore \mathbf{\hat{w}} = \left( \Phi^T \Phi \right)^{-1} \Phi^T \mathbf{y}$$$

Note that we are implicitly assuming that $\Phi^T \Phi$ is an invertible matrix. If either the number of linearly independent examples is less than the number of features, or if the features are not linearly independent, then $\Phi^T \Phi$ is not invertible.

This least squared solution is an estimator for $\mathbf{w}$. It represents the vector normal to the hyperplane that minimizes the sum of squared errors between the target values and the predictions.

However, this is not enough, we need to be sure of how confident we are in our predictions.

## Homoscedastic Model

Assume that target values $y_i$ are represented by random variables $Y_1, Y_2, \cdots, Y_{\tiny N}$ that are independent and identically distributed (i.i.d.). Then,

$$$Y_i = \langle \mathbf{w^{*}}, \mathbf{x_i} \rangle + \epsilon_i$$$

where $\mathbf{w^{*}}$ is the vector of true weights that generates the data and $\mathbf{\epsilon}_i \sim \mathcal{N}(0, \sigma^2)$ is an independent gaussian noise term.

We can write $\mathbf{Y}$ as:

\begin{align} &\mathbf{Y} = \Phi \mathbf{w^{*}} + \Large{\mathbf{\epsilon}}\\ \implies & \begin{pmatrix} Y_1 \\ Y_2 \\ \vdots \\ Y_{\tiny N} \end{pmatrix} = \begin{pmatrix} \langle \mathbf{x_1}, \mathbf{w^{*}} \rangle \\ \langle \mathbf{x_2}, \mathbf{w^{*}} \rangle \\ \vdots \\ \langle \mathbf{x_{\tiny N}}, \mathbf{w^{*}} \rangle \end{pmatrix} + \begin{pmatrix} \epsilon_1 \\ \epsilon_2 \\ \vdots \\ \epsilon_{\tiny N} \end{pmatrix}\\ \end{align}

Here, $\Large \mathbf{\epsilon}$ $\sim \mathcal{N}(\mathbf{0}, \sigma^2 I_{\tiny N})$ where $I_{\tiny N}$ is the $N \times N$ identity matrix.

We can show this as:

$\mathbb{E} \left[\begin{pmatrix} \epsilon_1 \\ \epsilon_2 \\ \vdots \\ \epsilon_{\tiny N} \end{pmatrix} \right] = \left[\begin{array}{c} \mathbb{E} \left( \epsilon_1 \right) \\ \mathbb{E} \left( \epsilon_2 \right) \\ \vdots \\ \mathbb{E} \left(\epsilon_{\tiny N}\right) \end{array}\right] = \mathbf{0}$

$\mathrm{Cov}(\mathbf{\Large{\epsilon}}) = \begin{pmatrix} \mathrm{Cov}(\epsilon_i, \epsilon_j) \end{pmatrix}_{1 \leq~i,~j~\leq N} = \begin{pmatrix} \sigma^2 & 0 & 0 & \cdots & 0 \\ 0 & \sigma^2 & 0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & \sigma^2 \end{pmatrix} = \sigma^2 I_{\tiny N}$

$\because \forall ~i \neq j \mathrm{: } \mathrm{Cov}(\epsilon_i, \epsilon_j) = 0$ and $\forall ~i = j \mathrm{~: Cov}(\epsilon_i, \epsilon_j) = \mathrm{Var}(\epsilon_i) = \sigma^2$

$\mathbf{\hat{w}}$ is our estimator for $\mathbf{w^{*}}$. We can write:

$$$\mathbf{\hat{w}} = \left( \Phi^T \Phi \right)^{-1} \Phi^T \mathbf{Y}$$$

Substituting value of $\mathbf{Y}$ from equation $(17)$, we can write:

\begin{align} &\mathbf{\hat{w}} = \left( \Phi^T \Phi \right)^{-1} \Phi^T \left( \Phi \mathbf{w^{*}} + \Large{\mathbf{\epsilon}} \right)\\ \implies &\mathbf{\hat{w}} = \left( \Phi^T \Phi \right)^{-1} \Phi^T \Phi \mathbf{w^{*}} + \left( \Phi^T \Phi \right)^{-1} \Phi^T \Large{\mathbf{\epsilon}}\\ \implies &\mathbf{\hat{w}} = \mathbf{w^{*}} + \left( \Phi^T \Phi \right)^{-1} \Phi^T \Large{\mathbf{\epsilon}} \end{align}

Then taking expectation of both sides of the equation $(22)$, we get:

\begin{align*} \implies &\mathbb{E} \left[ \mathbf{\hat{w}} \right] = \mathbb{E} \left[ \mathbf{w^{*}} \right] + \mathbb{E} \left[ \left( \Phi^T \Phi \right)^{-1} \Phi^T \Large{\mathbf{\epsilon}} \right]\\ \implies &\mathbb{E} \left[ \mathbf{\hat{w}} \right] = \mathbf{w^{*}} + \mathbb{E} \left[ \left( \Phi^T \Phi \right)^{-1} \Phi^T \Large{\mathbf{\epsilon}} \right]\\ \implies &\mathbb{E} \left[ \mathbf{\hat{w}} \right] = \mathbf{w^{*}} + \left( \Phi^T \Phi \right)^{-1} \Phi^T \mathbb{E} \left[ \Large{\mathbf{\epsilon}} \right]\\ \implies &\mathbb{E} \left[ \mathbf{\hat{w}} \right] = \mathbf{w^{*}} + \left( \Phi^T \Phi \right)^{-1} \Phi^T \mathbf{0}\\ \end{align*}
$$$\therefore \mathbb{E} \left[ \mathbf{\hat{w}} \right] = \mathbf{w^{*}}$$$

We can see that our least-squared estimator $\mathbf{\hat{w}}$ is unbiased in probability with the true $\mathbf{w^{*}}$.

#### Lemma

Any affine transformation of a gaussian vector $\mathbf{z} \sim \mathcal{N} (\mathbf{0}, \Sigma)$ is also a gaussian vector:

Then, if $A$ is a matrix (that represents a linear transformation):

$$$A\mathbf{z} \sim \mathcal{N} (\mathbf{0}, A \Sigma A^T)$$$

Then, if $A = \left( \Phi^T \Phi \right)^{-1} \Phi^T$:

\begin{align*} \mathbf{\hat{w}} &\sim \mathcal{N} ( \mathbf{w^{*}}, A \sigma^2 \mathbb{I}_N A^T )\\ &= \mathcal{N}( \mathbf{w^{*}}, \sigma^2 \left( \Phi^T \Phi \right)^{-1} \Phi^T ( \left( \Phi^T \Phi \right)^{-1} \Phi^T)^T)\\ &= \mathcal{N}( \mathbf{w^{*}}, \sigma^2 \left( \Phi^T \Phi \right)^{-1} \Phi^T \Phi \left( \Phi^T \Phi \right)^{-T})\\ &= \mathcal{N}( \mathbf{w^{*}}, \sigma^2 \left( \Phi^T \Phi \right)^{-1} \Phi^T \Phi \left( \Phi^T \Phi \right)^{-1}) ~[~\because\left(\Phi^T \Phi \right)^{T} = \left( \Phi^T \Phi \right)~] \end{align*}
$$$\therefore \mathbf{\hat{w}} \sim \mathcal{N}( \mathbf{w^{*}}, \sigma^2 \left( \Phi^T \Phi \right)^{-1} )$$$

## Confidence Interval

To compute confidence interval on the weights i.e. on the $i^{th}$ component of $\mathbf{\hat{w}} = \begin{pmatrix} \hat{w_0} \\ \hat{w_1} \\ \vdots \\ \hat{w_d} \end{pmatrix} \sim \mathcal{N}( \mathbf{w^{*}}, \sigma^2 \left( \Phi^T \Phi \right)^{-1} )$ , we define:

$S = \left( \Phi^T \Phi \right)^{-1} = \begin{pmatrix} s_{00} & s_{11} & \cdots & s_{1d} \\ s_{10} & s_{11} & \cdots & s_{1d} \\ \vdots & \vdots & \ddots & \vdots \\ s_{d0} & s_{d1} & \cdots & s_{dd} \end{pmatrix}$

Then, we can write, $\text{Var}(\hat{w}) = \sigma^2 S$, which implies:

$Var(\hat{w_i}) = \sigma^2 s_{ii}$

Now,

\begin{align*} \hat{w_i} &\sim \mathcal{N}( w^{*}_i, \sigma^2 s_{ii})\\ \implies \frac{\hat{w_i} - w^{*}_i}{\sigma \sqrt{s_{ii}}} &\sim \mathcal{N}(0, 1)\\ \end{align*}

Then, we can write:

\begin{align*} \mathbb{P} \left( -z_{\alpha/2} \leq \frac{\hat{w_i} - w^{*}_i}{\sigma \sqrt{s_{ii}}} \leq z_{\alpha/2} \right) &= 1 - \alpha\\ \implies \mathbb{P} \left( \hat{w_i} - z_{\alpha/2} \sigma \sqrt{s_{ii}} \leq w^{*}_i \leq \hat{w_i} + z_{\alpha/2} \sigma \sqrt{s_{ii}} \right) &= 1 - \alpha\\ \end{align*}

For example, say that we want to compute the $95\%$ confidence interval for the $i^{th}$ component of $\mathbf{\hat{w}}$, then $\alpha = 0.05$ and $z_{\alpha/2} = 1.96$:

\begin{align*} \implies \mathbb{P} \left( \hat{w_i} - 1.96 \sigma \sqrt{s_{ii}} \leq w^{*}_i \leq \hat{w_i} + 1.96 \sigma \sqrt{s_{ii}} \right) &= 0.95\\ \implies \mathbb{P} \left( w^{*}_i \in \left[ \hat{w_i} \pm 1.96 \sigma \sqrt{s_{ii}} ~\right] \right) &= 0.95\\ \end{align*}

Here, $\left[ \hat{w_i} \pm 1.96 \sigma \sqrt{s_{ii}} ~\right]$ is the $95\%$ confidence interval for the $i^{th}$ component of $\mathbf{\hat{w}}$.

### Practical Problem

In practice, we don't know the true $\sigma^2$ and we have to estimate it from the data. We can estimate it using the following formula:

$$$\hat{\sigma}^2 = \frac{1}{N - d - 1} \sum_{i=1}^{N} \left( Y_i - \langle \mathbf{\hat{w}}, \mathbf{x_i} \rangle \right)^2$$$

Here, $d$ is the number of features and $N$ is the number of samples.

The term $N - d - 1$ rather than $N$ in the denominator is used to make $\hat{\sigma}^2$ an unbiased estimate of $\sigma^2$.

Now, the empirical variance of the residual is nearly equal to $\sigma^2$. The term $\left( \frac{\hat{w_i} - w^{*}_i}{\hat{\sigma} \sqrt{s_{ii}}} \right)$ is now asymptotically gaussian with mean $0$ and variance $1$.

Notes

• If the value of $N$ is small, it follows a t-distribution (Student distribution). The exact Confidence Intervals can even be derived using Cochran's theorem.
• Our math for confidence intervals relies on the assumption that our data is homoscedastic. In the case that it is not, we can compute the confidence intervals empirically using the bootstrap method, which is based on resampling and the law of large numbers.

### Regularization

Currently, we are using the following loss function:

$$$\mathcal{L}(\mathbf{w}) = \frac{1}{2N} \| \mathbf{y} - \Phi \mathbf{w}\|^2$$$

We can also add a regularization term in the loss function, to prevent overfitting:

$$$\mathcal{L}(\mathbf{w}) = \frac{1}{2N} \| \mathbf{y} - \Phi \mathbf{w}\|^2 + \frac{\lambda}{2} \| \mathbf{w} \|^2$$$

This is called Ridge or L2 Regularization. Here, $\lambda$ is the regularization parameter. It is a hyperparameter and can be tuned using cross-validation.

Note: We can also use other regularization methods like lasso (L1) regularization, square-root lasso, etc.

Now, to find a value of $\mathbf{w}$ that minimizes the loss function, we will solve:

$\begin{equation*} \nabla \mathcal{L}(\mathbf{w}) = 0 \end{equation*}$
\begin{align*} &\implies \nabla_w \left( \frac{1}{2N} \| \mathbf{y} - \Phi \mathbf{w}\|^2 + \frac{\lambda}{2} \| \mathbf{w} \|^2 \right) = 0\\ &\implies \frac{1}{N} \Phi^T \left( \mathbf{y} - \Phi \mathbf{w} \right) + \lambda \mathbf{w} = 0\\ &\implies \Phi^T \Phi \mathbf{w} + N \lambda \mathbf{w} = \Phi^T \mathbf{y}\\ &\implies \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right) \mathbf{w} = \Phi^T \mathbf{y}\\ \end{align*}
$$$\therefore \mathbf{\hat{w}_\lambda} = \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \mathbf{y}$$$

Note: Now, even if $d > N$, $\left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1}$ is well defined because of the shift.

### Prediction Error

Let's now look at the impact $\lambda$ on the generalization error.

\begin{align} y_i - \hat{y_i} &= \langle \mathbf{w}^*, \mathbf{x_i} \rangle + \epsilon_i - \langle \mathbf{\hat{w_\lambda}}, \mathbf{x_i} \rangle\\ &= \langle \mathbf{w}^* - \mathbf{\hat{w}_\lambda}, \mathbf{x_i} \rangle + \epsilon_i\\ \end{align}

Then,

\begin{align*} \mathbf{w}^* - \mathbf{\hat{w}_\lambda} &= \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \mathbf{y}\\ &= \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \left( \Phi \mathbf{w}^* + \epsilon \right)\\ &= \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \Phi \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon\\ &= \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \textcolor{#01B636}{(} \Phi^T \Phi \textcolor{#01B636}{+ N \lambda \mathbb{I_d} )} \mathbf{w}^* \textcolor{#E63E6D}{+ \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} N \lambda \mathbf{w}^*} - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon\\ &= \textcolor{#01B636}{\mathbf{w}^*} \textcolor{#E63E6D}{- \mathbb{I_d} \mathbf{w}^*} + \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} N \lambda \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon\\ &= \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} N \lambda \mathbf{w}^* - \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon \end{align*}

Substituting this value in the above equation, we get:

\begin{align*} y_i - \hat{y_i} &= \textcolor{#C060A1}{\langle N \lambda \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \mathbf{w}^*, \mathbf{x_i} \rangle} - \textcolor{#03C988}{\langle \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon, \mathbf{x_i} \rangle} + \textcolor{8B9A46}{\epsilon_i}\\ \end{align*}

Here:

• $\textcolor{#C060A1}{\langle N \lambda \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \mathbf{w}^*, \mathbf{x_i} \rangle}$ is the non-zero bias term, which is deterministic. (It is $0$ if $\lambda = 0$.)
• $\textcolor{#03C988}{\langle \left( \Phi^T \Phi + N \lambda \mathbb{I_d} \right)^{-1} \Phi^T \epsilon, \mathbf{x_i} \rangle}$ is the variance term.
• $\textcolor{8B9A46}{\epsilon_i}$ is the noise term which is uncontrollable.

Here, if we take the expectation of $y_i - \hat{y_i}$, we get a non-zero term, which is the bias term. It's a pity because our non-regularized model had an unbiased least squared estimator (expectation was the ground truth). Therefore, by introducing a bias in our model, we are either underestimating or overestimating the ground truth.

The interest of introducing a bias in our model is that it enables us to control the variance term. Therefore, with a small $\lambda$, we have a high variance and a low bias. On the other hand, with a large $\lambda$, we have a low variance and a high bias. We call this tradeoff the bias-variance tradeoff.