148 KiB
Week 37: Statistical interpretations and Resampling Methods
Morten Hjorth-Jensen, Department of Physics, University of Oslo and Department of Physics and Astronomy and Facility for Rare Isotope Beams, Michigan State University
Date: Sep 18, 2023
Copyright 1999-2023, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
Plans for week 37
Material for the active learning sessions on Tuesday and Wednesday.
-
Lecture from last week on calculations of expectation values
-
Exercise for week 37
-
Work on project 1
-
See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session. This note is added at the end of these slides.
-
For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
Material for the lecture on Thursday September 7.
-
Resampling techniques, Bootstrap and cross validation and bias-variance tradeoff
-
Statistical interpretation of Ridge and Lasso regression
-
Readings and Videos:
-
Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap).
-
Material from last week and relevant for the weekly exercises
Linking the regression analysis with a statistical interpretation
We will now couple the discussions of ordinary least squares, Ridge
and Lasso regression with a statistical interpretation, that is we
move from a linear algebra analysis to a statistical analysis. In
particular, we will focus on what the regularization terms can result
in. We will amongst other things show that the regularization
parameter can reduce considerably the variance of the parameters
\beta.
The
advantage of doing linear regression is that we actually end up with
analytical expressions for several statistical quantities.
Standard least squares and Ridge regression allow us to
derive quantities like the variance and other expectation values in a
rather straightforward way.
It is assumed that $\varepsilon_i
\sim \mathcal{N}(0, \sigma^2)$ and the \varepsilon_{i} are
independent, i.e.:
\begin{align*}
\mbox{Cov}(\varepsilon_{i_1},
\varepsilon_{i_2}) & = \left\{ \begin{array}{lcc} \sigma^2 & \mbox{if}
& i_1 = i_2, \\ 0 & \mbox{if} & i_1 \not= i_2. \end{array} \right.
\end{align*}
The randomness of \varepsilon_i implies that
\mathbf{y}_i is also a random variable. In particular,
\mathbf{y}_i is normally distributed, because $\varepsilon_i \sim
\mathcal{N}(0, \sigma^2)$ and \mathbf{X}_{i,\ast} \, \boldsymbol{\beta} is a
non-random scalar. To specify the parameters of the distribution of
\mathbf{y}_i we need to calculate its first two moments.
Recall that \boldsymbol{X} is a matrix of dimensionality n\times p. The
notation above \mathbf{X}_{i,\ast} means that we are looking at the
row number i and perform a sum over all values p.
Assumptions made
The assumption we have made here can be summarized as (and this is going to be useful when we discuss the bias-variance trade off)
that there exists a function f(\boldsymbol{x}) and a normal distributed error \boldsymbol{\varepsilon}\sim \mathcal{N}(0, \sigma^2)
which describe our data
\boldsymbol{y} = f(\boldsymbol{x})+\boldsymbol{\varepsilon}
We approximate this function with our model from the solution of the linear regression equations, that is our
function f is approximated by \boldsymbol{\tilde{y}} where we want to minimize (\boldsymbol{y}-\boldsymbol{\tilde{y}})^2, our MSE, with
\boldsymbol{\tilde{y}} = \boldsymbol{X}\boldsymbol{\beta}.
Expectation value and variance
We can calculate the expectation value of \boldsymbol{y} for a given element i
\begin{align*}
\mathbb{E}(y_i) & =
\mathbb{E}(\mathbf{X}_{i, \ast} \, \boldsymbol{\beta}) + \mathbb{E}(\varepsilon_i)
\, \, \, = \, \, \, \mathbf{X}_{i, \ast} \, \beta,
\end{align*}
while its variance is
\begin{align*} \mbox{Var}(y_i) & = \mathbb{E} \{ [y_i
- \mathbb{E}(y_i)]^2 \} \, \, \, = \, \, \, \mathbb{E} ( y_i^2 ) -
[\mathbb{E}(y_i)]^2 \\ & = \mathbb{E} [ ( \mathbf{X}_{i, \ast} \,
\beta + \varepsilon_i )^2] - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 \\ &
= \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2 \varepsilon_i
\mathbf{X}_{i, \ast} \, \boldsymbol{\beta} + \varepsilon_i^2 ] - ( \mathbf{X}_{i,
\ast} \, \beta)^2 \\ & = ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2
\mathbb{E}(\varepsilon_i) \mathbf{X}_{i, \ast} \, \boldsymbol{\beta} +
\mathbb{E}(\varepsilon_i^2 ) - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2
\\ & = \mathbb{E}(\varepsilon_i^2 ) \, \, \, = \, \, \,
\mbox{Var}(\varepsilon_i) \, \, \, = \, \, \, \sigma^2.
\end{align*}
Hence, y_i \sim \mathcal{N}( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta}, \sigma^2), that is \boldsymbol{y} follows a normal distribution with
mean value \boldsymbol{X}\boldsymbol{\beta} and variance \sigma^2 (not be confused with the singular values of the SVD).
Expectation value and variance for \boldsymbol{\beta}
With the OLS expressions for the optimal parameters \boldsymbol{\hat{\beta}} we can evaluate the expectation value
\mathbb{E}(\boldsymbol{\hat{\beta}}) = \mathbb{E}[ (\mathbf{X}^{\top} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbb{E}[ \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1} \mathbf{X}^{T}\mathbf{X}\boldsymbol{\beta}=\boldsymbol{\beta}.
This means that the estimator of the regression parameters is unbiased.
We can also calculate the variance
The variance of the optimal value \boldsymbol{\hat{\beta}} is
\begin{eqnarray*}
\mbox{Var}(\boldsymbol{\hat{\beta}}) & = & \mathbb{E} \{ [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})] [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})]^{T} \}
\\
& = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{y} - \boldsymbol{\beta}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{y} - \boldsymbol{\beta}]^{T} \}
\\
% & = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{y}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{y}]^{T} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T}
% \\
% & = & \mathbb{E} \{ (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{y} \, \mathbf{y}^{T} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T}
% \\
& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \mathbb{E} \{ \mathbf{y} \, \mathbf{y}^{T} \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T}
\\
& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \{ \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} \, \mathbf{X}^{T} + \sigma^2 \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T}
% \\
% & = & (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^T \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T % \mathbf{X})^{-1}
% \\
% & & + \, \, \sigma^2 \, (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T \mathbf{X})^{-1} - \boldsymbol{\beta} \boldsymbol{\beta}^T
\\
& = & \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} + \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T}
\, \, \, = \, \, \, \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1},
\end{eqnarray*}
where we have used that $\mathbb{E} (\mathbf{y} \mathbf{y}^{T}) =
\mathbf{X} , \boldsymbol{\beta} , \boldsymbol{\beta}^{T} , \mathbf{X}^{T} +
\sigma^2 , \mathbf{I}_{nn}$. From $\mbox{Var}(\boldsymbol{\beta}) = \sigma^2
, (\mathbf{X}^{T} \mathbf{X})^{-1}$, one obtains an estimate of the
variance of the estimate of the $j$-th regression coefficient:
\boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} . This may be used to
construct a confidence interval for the estimates.
In a similar way, we can obtain analytical expressions for say the
expectation values of the parameters \boldsymbol{\beta} and their variance
when we employ Ridge regression, allowing us again to define a confidence interval.
It is rather straightforward to show that
\mathbb{E} \big[ \hat{\boldsymbol{\beta}}^{\mathrm{Ridge}} \big]=(\mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I}_{pp})^{-1} (\mathbf{X}^{\top} \mathbf{X})\boldsymbol{\beta}.
We see clearly that
\mathbb{E} \big[ \hat{\boldsymbol{\beta}}^{\mathrm{Ridge}} \big] \not= \hat{\boldsymbol{\beta}}^{\mathrm{OLS}} for any \lambda > 0.
We can also compute the variance as
\mbox{Var}[\hat{\boldsymbol{\beta}}^{\mathrm{Ridge}}]=\sigma^2[ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1} \mathbf{X}^{T} \mathbf{X} \{ [ \mathbf{X}^{\top} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T},
and it is easy to see that if the parameter \lambda goes to infinity then the variance of Ridge parameters \boldsymbol{\beta} goes to zero.
With this, we can compute the difference
\mbox{Var}[\hat{\boldsymbol{\beta}}^{\mathrm{OLS}}]-\mbox{Var}(\hat{\boldsymbol{\beta}}^{\mathrm{Ridge}})=\sigma^2 [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}[ 2\lambda\mathbf{I} + \lambda^2 (\mathbf{X}^{T} \mathbf{X})^{-1} ] \{ [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}.
The difference is non-negative definite since each component of the
matrix product is non-negative definite.
This means the variance we obtain with the standard OLS will always for \lambda > 0 be larger than the variance of \boldsymbol{\beta} obtained with the Ridge estimator. This has interesting consequences when we discuss the so-called bias-variance trade-off below.
For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
Material for lecture Thursday September 14
Deriving OLS from a probability distribution
Our basic assumption when we derived the OLS equations was to assume
that our output is determined by a given continuous function
f(\boldsymbol{x}) and a random noise \boldsymbol{\epsilon} given by the normal
distribution with zero mean value and an undetermined variance
\sigma^2.
We found above that the outputs \boldsymbol{y} have a mean value given by
\boldsymbol{X}\hat{\boldsymbol{\beta}} and variance \sigma^2. Since the entries to
the design matrix are not stochastic variables, we can assume that the
probability distribution of our targets is also a normal distribution
but now with mean value \boldsymbol{X}\hat{\boldsymbol{\beta}}. This means that a
single output y_i is given by the Gaussian distribution
y_i\sim \mathcal{N}(\boldsymbol{X}_{i,*}\boldsymbol{\beta}, \sigma^2)=\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}.
Independent and Identically Distrubuted (iid)
We assume now that the various y_i values are stochastically distributed according to the above Gaussian distribution.
We define this distribution as
p(y_i, \boldsymbol{X}\vert\boldsymbol{\beta})=\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]},
which reads as finding the likelihood of an event y_i with the input variables \boldsymbol{X} given the parameters (to be determined) \boldsymbol{\beta}.
Since these events are assumed to be independent and identicall distributed we can build the probability distribution function (PDF) for all possible event \boldsymbol{y} as the product of the single events, that is we have
p(\boldsymbol{y},\boldsymbol{X}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}=\prod_{i=0}^{n-1}p(y_i,\boldsymbol{X}\vert\boldsymbol{\beta}).
We will write this in a more compact form reserving \boldsymbol{D} for the domain of events, including the ouputs (targets) and the inputs. That is
in case we have a simple one-dimensional input and output case
\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})].
In the more general case the various inputs should be replaced by the possible features represented by the input data set \boldsymbol{X}.
We can now rewrite the above probability as
p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}.
It is a conditional probability (see below) and reads as the likelihood of a domain of events \boldsymbol{D} given a set of parameters \boldsymbol{\beta}.
Maximum Likelihood Estimation (MLE)
In statistics, maximum likelihood estimation (MLE) is a method of estimating the parameters of an assumed probability distribution, given some observed data. This is achieved by maximizing a likelihood function so that, under the assumed statistical model, the observed data is the most probable.
We will assume here that our events are given by the above Gaussian
distribution and we will determine the optimal parameters \beta by
maximizing the above PDF. However, computing the derivatives of a
product function is cumbersome and can easily lead to overflow and/or
underflowproblems, with potentials for loss of numerical precision.
In practice, it is more convenient to maximize the logarithm of the PDF because it is a monotonically increasing function of the argument. Alternatively, and this will be our option, we will minimize the negative of the logarithm since this is a monotonically decreasing function.
Note also that maximization/minimization of the logarithm of the PDF is equivalent to the maximization/minimization of the function itself.
A new Cost Function
We could now define a new cost function to minimize, namely the negative logarithm of the above PDF
C(\boldsymbol{\beta}=-\log{\prod_{i=0}^{n-1}p(y_i,\boldsymbol{X}\vert\boldsymbol{\beta})}=-\sum_{i=0}^{n-1}\log{p(y_i,\boldsymbol{X}\vert\boldsymbol{\beta})},
which becomes
C(\boldsymbol{\beta}=\frac{n}{2}\log{2\pi\sigma^2}+\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}.
Taking the derivative of the new cost function with respect to the parameters \beta we recognize our familiar OLS equation, namely
\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right) =0,
which leads to the well-known OLS equation for the optimal paramters \beta
\hat{\boldsymbol{\beta}}^{\mathrm{OLS}}=\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}!
Before we make a similar analysis for Ridge and Lasso regression, we need a short reminder on statistics.
More basic Statistics and Bayes' theorem
A central theorem in statistics is Bayes' theorem. This theorem plays a similar role as the good old Pythagoras' theorem in geometry. Bayes' theorem is extremely simple to derive. But to do so we need some basic axioms from statistics.
Assume we have two domains of events X=[x_0,x_1,\dots,x_{n-1}] and Y=[y_0,y_1,\dots,y_{n-1}].
We define also the likelihood for X and Y as p(X) and p(Y) respectively.
The likelihood of a specific event x_i (or y_i) is then written as p(X=x_i) or just p(x_i)=p_i.
Union of events is given by.
p(X \cup Y)= p(X)+p(Y)-p(X \cap Y).
The product rule (aka joint probability) is given by.
p(X \cup Y)= p(X,Y)= p(X\vert Y)p(Y)=p(Y\vert X)p(X),
where we read p(X\vert Y) as the likelihood of obtaining X given Y.
If we have independent events then p(X,Y)=p(X)p(Y).
Marginal Probability
The marginal probability is defined in terms of only one of the set of variables X,Y. For a discrete probability we have
p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i).
Conditional Probability
The conditional probability, if p(Y) > 0, is
p(X\vert Y)= \frac{p(X,Y)}{p(Y)}=\frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}.
Bayes' Theorem
If we combine the conditional probability with the marginal probability and the standard product rule, we have
p(X\vert Y)= \frac{p(X,Y)}{p(Y)},
which we can rewrite as
p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert X)p(X)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)},
which is Bayes' theorem. It allows us to evaluate the uncertainty in in X after we have observed Y. We can easily interchange X with Y.
Interpretations of Bayes' Theorem
The quantity p(Y\vert X) on the right-hand side of the theorem is
evaluated for the observed data Y and can be viewed as a function of
the parameter space represented by X. This function is not
necesseraly normalized and is normally called the likelihood function.
The function p(X) on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution.
Let us try to illustrate Bayes' theorem through an example.
Example of Usage of Bayes' theorem
Let us suppose that you are undergoing a series of mammography scans in
order to rule out possible breast cancer cases. We define the
sensitivity for a positive event by the variable X. It takes binary
values with X=1 representing a positive event and X=0 being a
negative event. We reserve Y as a classification parameter for
either a negative or a positive breast cancer confirmation. (Short note on wordings: positive here means having breast cancer, although none of us would consider this being a positive thing).
We let Y=1 represent the the case of having breast cancer and Y=0 as not.
Let us assume that if you have breast cancer, the test will be positive with a probability of 0.8, that is we have
p(X=1\vert Y=1) =0.8.
This obviously sounds scary since many would conclude that if the test is positive, there is a likelihood of 80\% for having cancer.
It is however not correct, as the following Bayesian analysis shows.
Doing it correctly
If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. Let us assume that the prior probability in the population as a whole is
p(Y=1) =0.004.
We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have
p(X=1\vert Y=0) =0.1.
Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute
p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031.
That is, in case of a positive test, there is only a 3\% chance of having breast cancer!
Bayes' Theorem and Ridge and Lasso Regression
Using Bayes' theorem we can gain a better intuition about Ridge and Lasso regression.
For ordinary least squares we postulated that the maximum likelihood for the doamin of events \boldsymbol{D} (one-dimensional case)
\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})],
is given by
p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}.
In Bayes' theorem this function plays the role of the so-called likelihood. We could now ask the question what is the posterior probability of a parameter set \boldsymbol{\beta} given a domain of events \boldsymbol{D}? That is, how can we define the posterior probability
p(\boldsymbol{\beta}\vert\boldsymbol{D}).
Bayes' theorem comes to our rescue here since (omitting the normalization constant)
p(\boldsymbol{\beta}\vert\boldsymbol{D})\propto p(\boldsymbol{D}\vert\boldsymbol{\beta})p(\boldsymbol{\beta}).
We have a model for p(\boldsymbol{D}\vert\boldsymbol{\beta}) but need one for the prior p(\boldsymbol{\beta}!
Ridge and Bayes
With the posterior probability defined by a likelihood which we have already modeled and an unknown prior, we are now ready to make additional models for the prior.
We can, based on our discussions of the variance of \boldsymbol{\beta} and the mean value, assume that the prior for the values \boldsymbol{\beta} is given by a Gaussian with mean value zero and variance \tau^2, that is
p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\beta_j^2}{2\tau^2}\right)}.
Our posterior probability becomes then (omitting the normalization factor which is just a constant)
p(\boldsymbol{\beta\vert\boldsymbol{D})}=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}\prod_{j=0}^{p-1}\exp{\left(-\frac{\beta_j^2}{2\tau^2}\right)}.
We can now optimize this quantity with respect to \boldsymbol{\beta}. As we
did for OLS, this is most conveniently done by taking the negative
logarithm of the posterior probability. Doing so and leaving out the
constants terms that do not depend on \beta, we have
C(\boldsymbol{\beta})=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\frac{1}{2\tau^2}\vert\vert\boldsymbol{\beta}\vert\vert_2^2,
and replacing 1/2\tau^2 with \lambda we have
C(\boldsymbol{\beta})=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\lambda\vert\vert\boldsymbol{\beta}\vert\vert_2^2,
which is our Ridge cost function! Nice, isn't it?
Lasso and Bayes
To derive the Lasso cost function, we simply replace the Gaussian prior with an exponential distribution (Laplace in this case) with zero mean value, that is
p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}.
Our posterior probability becomes then (omitting the normalization factor which is just a constant)
p(\boldsymbol{\beta}\vert\boldsymbol{D})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}.
Taking the negative
logarithm of the posterior probability and leaving out the
constants terms that do not depend on \beta, we have
C(\boldsymbol{\beta}=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\frac{1}{\tau}\vert\vert\boldsymbol{\beta}\vert\vert_1,
and replacing 1/\tau with \lambda we have
C(\boldsymbol{\beta}=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\lambda\vert\vert\boldsymbol{\beta}\vert\vert_1,