diff --git a/doc/pub/week37/html/._week37-bs000.html b/doc/pub/week37/html/._week37-bs000.html index 2ae1b501d..8f20641eb 100644 --- a/doc/pub/week37/html/._week37-bs000.html +++ b/doc/pub/week37/html/._week37-bs000.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
-

 

 

 

- - - -
-

Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

+
+

Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

+
-

-

Morten Hjorth-Jensen [1, 2]
- -

+

+[1] Department of Physics, University of Oslo +
+
+[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
+
+
+

Aug 23, 2022

+
+
-
[1] Department of Physics, University of Oslo
-
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
-

-

Sep 28, 2021

-
-

Read »

@@ -325,25 +313,18 @@ MathJax.Hub.Config({
  • »
  • -
    - - -
    - © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week37/html/._week37-bs001.html b/doc/pub/week37/html/._week37-bs001.html index 76fd2118a..2101a0d4c 100644 --- a/doc/pub/week37/html/._week37-bs001.html +++ b/doc/pub/week37/html/._week37-bs001.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - -
    -
    -

     

     

     

    - -

    Plans for week 37

    - -Recommended Reading: - +

    Recommended Reading:

    1. Lectures on Resampling methods (these lectures)
    2. Bishop 1.3 (cross-validation) and 3.2 (bias-variance tradeoff)
    3. Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap). This chapter is better than Bishop's on these topics. Goodfellow et al discuss this in a superficial way in sections 5.2-5.5.
    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs002.html b/doc/pub/week37/html/._week37-bs002.html index a67359222..308a0625f 100644 --- a/doc/pub/week37/html/._week37-bs002.html +++ b/doc/pub/week37/html/._week37-bs002.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - +

    Thursday September 15, Summary of Ridge and Lasso Regression and start Resampling methods

    -

    Thursday September 16, Summary of Ridge and Lasso Regression and start Resampling methods

    - -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs003.html b/doc/pub/week37/html/._week37-bs003.html index dd442db40..1d30f26fa 100644 --- a/doc/pub/week37/html/._week37-bs003.html +++ b/doc/pub/week37/html/._week37-bs003.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Deriving OLS from a probability distribution

    -

    -Our basic assumption when we derived the OLS equations was to assume +

    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 +

    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]}. $$ -

    +

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs004.html b/doc/pub/week37/html/._week37-bs004.html index 98eeeda72..b7811b617 100644 --- a/doc/pub/week37/html/._week37-bs004.html +++ b/doc/pub/week37/html/._week37-bs004.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Independent and Identically Distrubuted (iid)

    -

    -We assume now that the various \( y_i \) values are stochastically distributed according to the above Gaussian distribution. +

    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} \). +

    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 +

    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 +

    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} \). +

    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} \). +

    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} \).

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs005.html b/doc/pub/week37/html/._week37-bs005.html index c83d6ece9..7d317a45b 100644 --- a/doc/pub/week37/html/._week37-bs005.html +++ b/doc/pub/week37/html/._week37-bs005.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Maximum Likelihood Estimation (MLE)

    -

    -In statistics, maximum likelihood estimation (MLE) is a method of +

    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. +data is the most probable. +

    -

    -We will assume here that our events are given by the above Gaussian +

    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 +

    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 +

    Note also that maximization/minimization of the logarithm of the PDF is equivalent to the maximization/minimization of the function itself. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs006.html b/doc/pub/week37/html/._week37-bs006.html index f301bcf3f..bce74449a 100644 --- a/doc/pub/week37/html/._week37-bs006.html +++ b/doc/pub/week37/html/._week37-bs006.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    A new Cost Function

    -

    -We could now define a new cost function to minimize, namely the negative logarithm of the above PDF +

    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 +

    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 +

    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 \) +

    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}! $$ -

    +

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs007.html b/doc/pub/week37/html/._week37-bs007.html index 91555da7f..d21af49a4 100644 --- a/doc/pub/week37/html/._week37-bs007.html +++ b/doc/pub/week37/html/._week37-bs007.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Bayes' Theorem

    -

    -If we combine the conditional probability with the marginal probability and the standard product rule, we have +

    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 +

    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 \). +

    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 \).

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs008.html b/doc/pub/week37/html/._week37-bs008.html index c2ab313ea..d96bf602d 100644 --- a/doc/pub/week37/html/._week37-bs008.html +++ b/doc/pub/week37/html/._week37-bs008.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Interpretations of Bayes' Theorem

    -

    -The quantity \( p(Y\vert X) \) on the right-hand side of the theorem is +

    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. +

    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.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs009.html b/doc/pub/week37/html/._week37-bs009.html index 9f1d723ec..82c3c9405 100644 --- a/doc/pub/week37/html/._week37-bs009.html +++ b/doc/pub/week37/html/._week37-bs009.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Test Function for what happens with OLS, Ridge and Lasso

    -

    -We will play around with a study of the values for the optimal +

    We will play around with a study of the values for the optimal parameters \( \boldsymbol{\beta} \) using OLS, Ridge and Lasso regression. For OLS, you will notice as function of the noise and polynomial degree, that the parameters \( \beta \) will fluctuate from order to order in the polynomial fit and that for larger and larger polynomial degrees of freedom, the parameters will tend to increase in value for OLS. +

    -

    -For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one. +

    For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one.

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import train_test_split
     from sklearn import linear_model
    @@ -356,11 +347,23 @@ plt.xlabel('
     plt.ylabel('MSE')
     plt.legend()
     plt.show()
    -
    -

    -How can we understand this? +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    How can we understand this?

    -

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs010.html b/doc/pub/week37/html/._week37-bs010.html index 830e0ee10..b213ab5fc 100644 --- a/doc/pub/week37/html/._week37-bs010.html +++ b/doc/pub/week37/html/._week37-bs010.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Rerunning the above code

    -

    -Let us write out the values of the coefficients \( \beta_i \) as functions +

    Let us write out the values of the coefficients \( \beta_i \) as functions of the polynomial degree and noise. We will focus only on the Ridge results and some few selected values of the hyperparameter \( \lambda \). +

    -

    -If we don't include any noise and run this code for different values +

    If we don't include any noise and run this code for different values of the polynomial degree, we notice that the results for \( \beta_i \) do not show great changes from one order to the next. This is an indication that for higher polynomial orders, our parameters become less important. +

    -

    -If we however add noise, what happens is that the polynomial fit is +

    If we however add noise, what happens is that the polynomial fit is trying to adjust the fit to traverse in the best possible way all data points. This can lead to large fluctuations in the parameters \( \beta_i \) as functions of polynomial order. It will also be reflected @@ -301,11 +288,16 @@ in a larger value of the variance of each parameter \( \beta_i \). What Ridge regression (and Lasso as well) are doing then is to try to quench the fluctuations in the parameters of \( \beta_i \) which have a large variance (normally for higher orders in the polynomial). +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     import matplotlib.pyplot as plt
    @@ -343,8 +335,22 @@ lambdas = np.= pd.DataFrame(Coeffs)
         BetaValues.columns = ['beta']
         display(BetaValues)    
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs011.html b/doc/pub/week37/html/._week37-bs011.html index fe3fe6475..322b9f459 100644 --- a/doc/pub/week37/html/._week37-bs011.html +++ b/doc/pub/week37/html/._week37-bs011.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Invoking Bayes' theorem

    -

    -Using Bayes' theorem we can gain a better intuition about 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) +

    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 +

    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 +

    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) +

    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} \)! +

    We have a model for \( p(\boldsymbol{D}\vert\boldsymbol{\beta}) \) but need one for the prior \( p(\boldsymbol{\beta} \)!

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs012.html b/doc/pub/week37/html/._week37-bs012.html index e18f4bb7c..b1904a778 100644 --- a/doc/pub/week37/html/._week37-bs012.html +++ b/doc/pub/week37/html/._week37-bs012.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Ridge and Bayes

    -

    -With the posterior probability defined by a likelihood which we have +

    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 +

    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) +

    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 +

    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 +

    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? +

    which is our Ridge cost function! Nice, isn't it?

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs013.html b/doc/pub/week37/html/._week37-bs013.html index d9649b431..b501aeee3 100644 --- a/doc/pub/week37/html/._week37-bs013.html +++ b/doc/pub/week37/html/._week37-bs013.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    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 +

    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) +

    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 +

    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 +

    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, $$ -which is our Lasso cost function! +

    which is our Lasso cost function!

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs014.html b/doc/pub/week37/html/._week37-bs014.html index 81a7f522b..52f9d89c7 100644 --- a/doc/pub/week37/html/._week37-bs014.html +++ b/doc/pub/week37/html/._week37-bs014.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Why resampling methods

    -

    -Before we proceed, we need to rethink what we have been doing. In our +

    Before we proceed, we need to rethink what we have been doing. In our eager to fit the data, we have omitted several important elements in our regression analysis. In what follows we will - +

    1. look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff
    2. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more
    +

    and discuss how to select a given model (one of the difficult parts in machine learning).

    -and discuss how to select a given model (one of the difficult parts in machine learning). - -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs015.html b/doc/pub/week37/html/._week37-bs015.html index c856e1f4c..66865e6eb 100644 --- a/doc/pub/week37/html/._week37-bs015.html +++ b/doc/pub/week37/html/._week37-bs015.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods

    -

    -Resampling methods are an indispensable tool in modern + +

    Resampling methods are an indispensable tool in modern statistics. They involve repeatedly drawing samples from a training set and refitting a model of interest on each sample in order to obtain additional information about the fitted model. For example, in @@ -292,24 +280,20 @@ regression to each new sample, and then examine the extent to which the resulting fits differ. Such an approach may allow us to obtain information that would not be available from fitting the model only once using the original training sample. +

    -

    -Two resampling methods are often used in Machine Learning analyses, - +

    Two resampling methods are often used in Machine Learning analyses,

    1. The bootstrap method
    2. and Cross-Validation
    - -In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular -cross-validation and the bootstrap method. - -

    +

    In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular +cross-validation and the bootstrap method. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs016.html b/doc/pub/week37/html/._week37-bs016.html index 3215ffe84..65d5a43b2 100644 --- a/doc/pub/week37/html/._week37-bs016.html +++ b/doc/pub/week37/html/._week37-bs016.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling approaches can be computationally expensive

    -

    + -

    -Resampling approaches can be computationally expensive, because they +

    Resampling approaches can be computationally expensive, because they involve fitting the same statistical method multiple times using different subsets of the training data. However, due to recent advances in computing power, the computational requirements of @@ -299,13 +286,11 @@ of flexibility. The process of evaluating a model’s performance is known as model assessment, whereas the process of selecting the proper level of flexibility for a model is known as model selection. The bootstrap is widely used. - -

    +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs017.html b/doc/pub/week37/html/._week37-bs017.html index 83b86d50e..3a5a8bb66 100644 --- a/doc/pub/week37/html/._week37-bs017.html +++ b/doc/pub/week37/html/._week37-bs017.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Why resampling methods ?

    -

    +

    • Our simulations can be treated as computer experiments. This is particularly the case for Monte Carlo methods which are widely used in statistical analyses.
    • @@ -290,9 +278,8 @@ MathJax.Hub.Config({
    + - -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs018.html b/doc/pub/week37/html/._week37-bs018.html index 04ef0b537..90da25c1d 100644 --- a/doc/pub/week37/html/._week37-bs018.html +++ b/doc/pub/week37/html/._week37-bs018.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Statistical analysis

    -

    +

    • As in other experiments, many numerical experiments have two classes of errors:
    • -
      • Statistical errors
      • Systematical errors
      -
    • Statistical errors can be estimated using standard tools from statistics
    • Systematical errors are method specific and must be treated differently from case to case.
    + - -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs019.html b/doc/pub/week37/html/._week37-bs019.html index 945f831c7..18f0df998 100644 --- a/doc/pub/week37/html/._week37-bs019.html +++ b/doc/pub/week37/html/._week37-bs019.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods

    -

    -With all these analytical equations for both the OLS and Ridge +

    With all these analytical equations for both the OLS and Ridge regression, we will now outline how to assess a given model. This will lead to a discussion of the so-called bias-variance tradeoff (see below) and so-called resampling methods. +

    -

    -One of the quantities we have discussed as a way to measure errors is +

    One of the quantities we have discussed as a way to measure errors is the mean-squared error (MSE), mainly used for fitting of continuous functions. Another choice is the absolute error. +

    -

    -In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, +

    In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, we discuss the - +

    1. prediction error or simply the test error \( \mathrm{Err_{Test}} \), where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the
    2. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    - -As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. +

    As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. For a certain level of complexity the test error will reach minimum, before starting to increase again. The training error reaches a saturation. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs020.html b/doc/pub/week37/html/._week37-bs020.html index 78a31af56..718f0586a 100644 --- a/doc/pub/week37/html/._week37-bs020.html +++ b/doc/pub/week37/html/._week37-bs020.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Jackknife and Bootstrap

    -

    -Two famous -resampling methods are the independent bootstrap and the jackknife. +

    Two famous +resampling methods are the independent bootstrap and the jackknife. +

    -

    -The jackknife is a special case of the independent bootstrap. Still, the jackknife was made +

    The jackknife is a special case of the independent bootstrap. Still, the jackknife was made popular prior to the independent bootstrap. And as the popularity of the independent bootstrap soared, new variants, such as the dependent bootstrap have also been developed.. +

    -

    -The Jackknife and independent bootstrap work for +

    The Jackknife and independent bootstrap work for independent, identically distributed random variables. If these conditions are not satisfied, the methods will fail. Yet, it should be said that if the data are independent, identically distributed, and we only want to estimate the variance of \( \overline{X} \) (which often is the case), then there is no -need for bootstrapping. +need for bootstrapping. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs021.html b/doc/pub/week37/html/._week37-bs021.html index 7b3282268..a38c849bf 100644 --- a/doc/pub/week37/html/._week37-bs021.html +++ b/doc/pub/week37/html/._week37-bs021.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Jackknife

    -

    -The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). +

    The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). The jackknife is a resampling method where we systematically leave out one observation from the vector of observed values \( \boldsymbol{x} = (x_1,x_2,\cdots,X_n) \). Let \( \boldsymbol{x}_i \) denote the vector +

    $$ \boldsymbol{x}_i = (x_1,x_2,\cdots,x_{i-1},x_{i+1},\cdots,x_n), $$ -

    -which equals the vector \( \boldsymbol{x} \) with the exception that observation +

    which equals the vector \( \boldsymbol{x} \) with the exception that observation number \( i \) is left out. Using this notation, define \( \widehat{\beta}_i \) to be the estimator -\( \widehat{\beta} \) computed using \( \vec{X}_i \). +\( \widehat{\beta} \) computed using \( \vec{X}_i \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs022.html b/doc/pub/week37/html/._week37-bs022.html index d48d82e84..960cf3c48 100644 --- a/doc/pub/week37/html/._week37-bs022.html +++ b/doc/pub/week37/html/._week37-bs022.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Jackknife code example

    -

    -

    from numpy import *
    +
    +
    +
    +
    +
    +
    from numpy import *
     from numpy.random import randint, randn
     from time import time
     
    @@ -310,8 +302,22 @@ datapoints = 10
     x = mu + sigma*random.randn(datapoints)
     # jackknife returns the data sample                                                                                                                                                
     t = jackknife(x, stat)
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs023.html b/doc/pub/week37/html/._week37-bs023.html index 8ac13685a..cde9ffc08 100644 --- a/doc/pub/week37/html/._week37-bs023.html +++ b/doc/pub/week37/html/._week37-bs023.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Bootstrap

    -

    -Bootstrapping is a non-parametric approach to statistical inference + +

    Bootstrapping is a non-parametric approach to statistical inference that substitutes computation for more traditional distributional assumptions and asymptotic results. Bootstrapping offers a number of advantages: - +

    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small.
    3. @@ -297,13 +285,10 @@ advantages:
    -

    -The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani. +

    The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani.

    -

    -Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem. +

    Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs024.html b/doc/pub/week37/html/._week37-bs024.html index 34768f990..0b8bbf169 100644 --- a/doc/pub/week37/html/._week37-bs024.html +++ b/doc/pub/week37/html/._week37-bs024.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - -
    -
    -

     

     

     

    - -

    The Central Limit Theorem

    -

    -Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) +

    Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) of averages \( \mathbb{E}[x_i] \). Each mean value \( \mathbb{E}[x_i] \) is viewed as the average of a specific measurement, e.g., throwing dice 100 times and then taking the average value, or producing a certain amount of random numbers. For notational ease, we set \( \mathbb{E}[x_i]=x_i \) in the discussion which follows. We do the same for \( \mathbb{E}[z]=z \). +

    -

    -If we compute the mean \( z \) of \( m \) such mean values \( x_i \) +

    If we compute the mean \( z \) of \( m \) such mean values \( x_i \)

    $$ z=\frac{x_1+x_2+\dots+x_m}{m}, $$ -the question we pose is which is the PDF of the new variable \( z \). +

    the question we pose is which is the PDF of the new variable \( z \).

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs025.html b/doc/pub/week37/html/._week37-bs025.html index e3d674725..5902378fa 100644 --- a/doc/pub/week37/html/._week37-bs025.html +++ b/doc/pub/week37/html/._week37-bs025.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Finding the Limit

    -

    -The probability of obtaining an average value \( z \) is the product of the +

    The probability of obtaining an average value \( z \) is the product of the probabilities of obtaining arbitrary individual mean values \( x_i \), but with the constraint that the average is \( z \). We can express this through the following expression +

    $$ \tilde{p}(z)=\int dx_1p(x_1)\int dx_2p(x_2)\dots\int dx_mp(x_m) \delta(z-\frac{x_1+x_2+\dots+x_m}{m}), $$ -where the \( \delta \)-function enbodies the constraint that the mean is \( z \). +

    where the \( \delta \)-function enbodies the constraint that the mean is \( z \). All measurements that lead to each individual \( x_i \) are expected to be independent, which in turn means that we can express \( \tilde{p} \) as the product of individual \( p(x_i) \). The independence assumption is important in the derivation of the central limit theorem. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs026.html b/doc/pub/week37/html/._week37-bs026.html index 1b4b82de4..93c7da03e 100644 --- a/doc/pub/week37/html/._week37-bs026.html +++ b/doc/pub/week37/html/._week37-bs026.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Rewriting the \( \delta \)-function

    -

    -If we use the integral expression for the \( \delta \)-function +

    If we use the integral expression for the \( \delta \)-function

    $$ \delta(z-\frac{x_1+x_2+\dots+x_m}{m})=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\frac{x_1+x_2+\dots+x_m}{m})\right)}, $$ -and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value +

    and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value we arrive at +

    $$ \tilde{p}(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\mu)\right)}\left[\int_{-\infty}^{\infty} dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m, $$ -with the integral over \( x \) resulting in +

    with the integral over \( x \) resulting in

    $$ \int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}= @@ -304,7 +292,7 @@ $$ \left[1+\frac{iq(\mu-x)}{m}-\frac{q^2(\mu-x)^2}{2m^2}+\dots\right]. $$ -

    +

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs027.html b/doc/pub/week37/html/._week37-bs027.html index edebb0273..fc38a630e 100644 --- a/doc/pub/week37/html/._week37-bs027.html +++ b/doc/pub/week37/html/._week37-bs027.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Identifying Terms

    -

    -The second term on the rhs disappears since this is just the mean and +

    The second term on the rhs disappears since this is just the mean and employing the definition of \( \sigma^2 \) we have +

    $$ \int_{-\infty}^{\infty}dxp(x)e^{\left(iq(\mu-x)/m\right)}= 1-\frac{q^2\sigma^2}{2m^2}+\dots, $$ -resulting in +

    resulting in

    $$ \left[\int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m\approx \left[1-\frac{q^2\sigma^2}{2m^2}+\dots \right]^m, $$ -and in the limit \( m\rightarrow \infty \) we obtain +

    and in the limit \( m\rightarrow \infty \) we obtain

    $$ \tilde{p}(z)=\frac{1}{\sqrt{2\pi}(\sigma/\sqrt{m})} \exp{\left(-\frac{(z-\mu)^2}{2(\sigma/\sqrt{m})^2}\right)}, $$ -which is the normal distribution with variance +

    which is the normal distribution with variance \( \sigma^2_m=\sigma^2/m \), where \( \sigma \) is the variance of the PDF \( p(x) \) -and \( \mu \) is also the mean of the PDF \( p(x) \). +and \( \mu \) is also the mean of the PDF \( p(x) \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs028.html b/doc/pub/week37/html/._week37-bs028.html index 1fe887f6d..1fadf67e3 100644 --- a/doc/pub/week37/html/._week37-bs028.html +++ b/doc/pub/week37/html/._week37-bs028.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Wrapping it up

    -

    -Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of +

    Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of the average of \( m \) random values corresponding to a PDF \( p(x) \) is a normal distribution whose mean is the mean value of the PDF \( p(x) \) and whose variance is the variance of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \). +

    -

    -The central limit theorem leads to the well-known expression for the +

    The central limit theorem leads to the well-known expression for the standard deviation, given by +

    $$ \sigma_m= \frac{\sigma}{\sqrt{m}}. $$ -

    -The latter is true only if the average value is known exactly. This is obtained in the limit +

    The latter is true only if the average value is known exactly. This is obtained in the limit \( m\rightarrow \infty \) only. Because the mean and the variance are measured quantities we obtain the familiar expression in statistics (the so-called Bessel correction) +

    $$ \sigma_m\approx \frac{\sigma}{\sqrt{m-1}}. $$ -

    -In many cases however the above estimate for the standard deviation, +

    In many cases however the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. Keep in mind that we have assumed that the variables \( x \) are independent and identically distributed. This is obviously not always the case. For example, the random numbers (or better pseudorandom numbers) we generate in various calculations do always exhibit some correlations. +

    -

    -The theorem is satisfied by a large class of PDFs. Note however that for a +

    The theorem is satisfied by a large class of PDFs. Note however that for a finite \( m \), it is not always possible to find a closed form /analytic expression for \( \tilde{p}(x) \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs029.html b/doc/pub/week37/html/._week37-bs029.html index c01e592e3..7ec7db238 100644 --- a/doc/pub/week37/html/._week37-bs029.html +++ b/doc/pub/week37/html/._week37-bs029.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Confidence Intervals

    -

    -Confidence intervals are used in statistics and represent a type of estimate +

    Confidence intervals are used in statistics and represent a type of estimate computed from the observed data. This gives a range of values for an unknown parameter such as the parameters \( \boldsymbol{\beta} \) from linear regression. +

    -

    -With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found +

    With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found \( \mathbb{E}(\boldsymbol{\beta}) = \boldsymbol{\beta} \), which means that the estimator of the regression parameters is unbiased. +

    -

    -We found also that the variance of the estimate of the \( j \)-th regression coefficient is +

    We found also that the variance of the estimate of the \( j \)-th regression coefficient is \( \boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} \). +

    -

    -This quantity will be used to +

    This quantity will be used to construct a confidence interval for the estimates. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs030.html b/doc/pub/week37/html/._week37-bs030.html index 543d7684f..ff309ba89 100644 --- a/doc/pub/week37/html/._week37-bs030.html +++ b/doc/pub/week37/html/._week37-bs030.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Standard Approach based on the Normal Distribution

    -

    -We will assume that the parameters \( \beta \) follow a normal +

    We will assume that the parameters \( \beta \) follow a normal distribution. We can then define the confidence interval. Here we will be using as shorthands \( \mu_{\beta} \) for the above mean value and \( \sigma_{\beta} \) for the standard deviation. We have then a confidence interval +

    $$ \left(\mu_{\beta}\pm \frac{z\sigma_{\beta}}{\sqrt{n}}\right), $$ -

    -where \( z \) defines the level of certainty (or confidence). For a normal +

    where \( z \) defines the level of certainty (or confidence). For a normal distribution typical parameters are \( z=2.576 \) which corresponds to a confidence of \( 99\% \) while \( z=1.96 \) corresponds to a confidence of \( 95\% \). A confidence level of \( 95\% \) is commonly used and it is normally referred to as a two-sigmas confidence level, that is we approximate \( z\approx 2 \). +

    -

    -For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications +

    For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications

    -

    -In this text you will also find an in-depth discussion of the -Bootstrap method, why it works and various theorems related to it. +

    In this text you will also find an in-depth discussion of the +Bootstrap method, why it works and various theorems related to it. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs031.html b/doc/pub/week37/html/._week37-bs031.html index 549612ce1..fc2ed7e73 100644 --- a/doc/pub/week37/html/._week37-bs031.html +++ b/doc/pub/week37/html/._week37-bs031.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Bootstrap background

    -

    -Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, +

    Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, \( \widehat{\beta} \) itself must be a random variable. Thus it has a pdf, call this function \( p(\boldsymbol{t}) \). The aim of the bootstrap is to estimate \( p(\boldsymbol{t}) \) by the relative frequency of @@ -289,9 +276,9 @@ estimate \( p(\boldsymbol{t}) \) by the relative frequency of in the place of \( p(\boldsymbol{t}) \). If the relative frequency closely resembles \( p(\vec{t}) \), then using numerics, it is straight forward to estimate all the interesting parameters of \( p(\boldsymbol{t}) \) using point -estimators. +estimators. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs032.html b/doc/pub/week37/html/._week37-bs032.html index 62de18bf4..059afe833 100644 --- a/doc/pub/week37/html/._week37-bs032.html +++ b/doc/pub/week37/html/._week37-bs032.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: More Bootstrap background

    -

    -In the case that \( \widehat{\beta} \) has +

    In the case that \( \widehat{\beta} \) has more than one component, and the components are independent, we use the same estimator on each component separately. If the probability density function of \( X_i \), \( p(x) \), had been known, then it would have been straightforward to do this by: - +

    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. Then using these numbers, we could compute a replica of \( \widehat{\beta} \) called \( \widehat{\beta}^* \).
    - -By repeated use of the above two points, many +

    By repeated use of the above two points, many estimates of \( \widehat{\beta} \) can be obtained. The idea is to use the relative frequency of \( \widehat{\beta}^* \) (think of a histogram) as an estimate of \( p(\boldsymbol{t}) \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs033.html b/doc/pub/week37/html/._week37-bs033.html index a395a63ef..e15f99e0c 100644 --- a/doc/pub/week37/html/._week37-bs033.html +++ b/doc/pub/week37/html/._week37-bs033.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Bootstrap approach

    -

    -But +

    But unless there is enough information available about the process that generated \( X_1,X_2,\cdots,X_n \), \( p(x) \) is in general unknown. Therefore, Efron in 1979 asked the question: What if we replace \( p(x) \) by the relative frequency of the observation \( X_i \)? +

    -

    -If we draw observations in accordance with +

    If we draw observations in accordance with the relative frequency of the observations, will we obtain the same result in some asymptotic sense? The answer is yes. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs034.html b/doc/pub/week37/html/._week37-bs034.html index e3703e88a..8560c1d80 100644 --- a/doc/pub/week37/html/._week37-bs034.html +++ b/doc/pub/week37/html/._week37-bs034.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Resampling methods: Bootstrap steps

    -

    -The independent bootstrap works like this: +

    The independent bootstrap works like this:

    1. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    2. @@ -289,8 +276,7 @@ The independent bootstrap works like this:
    3. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\beta}^* \) by evaluating \( \widehat \beta \) under the observations \( \boldsymbol{x}^* \).
    4. Repeat this process \( k \) times.
    - -When you are done, you can draw a histogram of the relative frequency +

    When you are done, you can draw a histogram of the relative frequency of \( \widehat \beta^* \). This is your estimate of the probability distribution \( p(t) \). Using this probability distribution you can estimate any statistics thereof. In principle you never draw the @@ -299,8 +285,8 @@ you use the estimators corresponding to the statistic of interest. For example, if you are interested in estimating the variance of \( \widehat \beta \), apply the etsimator \( \widehat \sigma^2 \) to the values \( \widehat \beta^* \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs035.html b/doc/pub/week37/html/._week37-bs035.html index 0ee213d9b..ff4fccac9 100644 --- a/doc/pub/week37/html/._week37-bs035.html +++ b/doc/pub/week37/html/._week37-bs035.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Code example for the Bootstrap method

    -

    -The following code starts with a Gaussian distribution with mean value +

    The following code starts with a Gaussian distribution with mean value \( \mu =100 \) and variance \( \sigma=15 \). We use this to generate the data used in the bootstrap analysis. The bootstrap analysis returns a data set after a given number of bootstrap operations (as many as we have @@ -293,11 +280,16 @@ centered around the mean value \( \mu=100 \) but with standard deviation this case the same as the number of original data points). The value of the standard deviation is what we expect from the central limit theorem. +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from time import time
     from scipy.stats import norm
     import matplotlib.pyplot as plt
    @@ -323,11 +315,23 @@ datapoints = 10
     x = mu + sigma*np.random.randn(datapoints)
     # bootstrap returns the data sample                                    
     t = bootstrap(x, datapoints)
    -
    -

    -We see that our new variance and from that the standard deviation, agrees with the central limit theorem. +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We see that our new variance and from that the standard deviation, agrees with the central limit theorem.

    -

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs036.html b/doc/pub/week37/html/._week37-bs036.html index 392c85c0e..a8565777e 100644 --- a/doc/pub/week37/html/._week37-bs036.html +++ b/doc/pub/week37/html/._week37-bs036.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Plotting the Histogram

    -

    -

    # the histogram of the bootstrapped data (normalized data if density = True)
    +
    +
    +
    +
    +
    +
    # the histogram of the bootstrapped data (normalized data if density = True)
     n, binsboot, patches = plt.hist(t, 50, density=True, facecolor='red', alpha=0.75)
     # add a 'best fit' line  
     y = norm.pdf(binsboot, np.mean(t), np.std(t))
    @@ -291,8 +283,22 @@ plt.xlabel('
     plt.ylabel('Probability')
     plt.grid(True)
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs037.html b/doc/pub/week37/html/._week37-bs037.html index 666ee94c7..77e1dd106 100644 --- a/doc/pub/week37/html/._week37-bs037.html +++ b/doc/pub/week37/html/._week37-bs037.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    The bias-variance tradeoff

    -

    -We will discuss the bias-variance tradeoff in the context of +

    We will discuss the bias-variance tradeoff in the context of continuous predictions such as regression. However, many of the intuitions and ideas discussed here also carry over to classification tasks. Consider a dataset \( \mathcal{D} \) consisting of the data -\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +

    -

    -Let us assume that the true data is generated from a noisy model +

    Let us assume that the true data is generated from a noisy model

    $$ \boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} $$ -

    -where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \). +

    where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \).

    -

    -In our derivation of the ordinary least squares method we defined then +

    In our derivation of the ordinary least squares method we defined then an approximation to the function \( f \) in terms of the parameters \( \boldsymbol{\beta} \) and the design matrix \( \boldsymbol{X} \) which embody our model, -that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +

    -

    -Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function +

    Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function

    $$ C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]. $$ -

    -We can rewrite this as +

    We can rewrite this as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2. $$ -

    -The three terms represent the square of the bias of the learning +

    The three terms represent the square of the bias of the learning method, which can be thought of as the error caused by the simplifying assumptions built into the method. The second term represents the variance of the chosen model and finally the last terms is variance of the error \( \boldsymbol{\epsilon} \). +

    -

    -To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). +

    To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). We use a more compact notation in terms of the expectation value +

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}})^2\right], $$ -and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get +

    and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}}+\mathbb{E}\left[\boldsymbol{\tilde{y}}\right]-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right], $$ -which, using the abovementioned expectation values can be rewritten as +

    which, using the abovementioned expectation values can be rewritten as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{y}-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\boldsymbol{\tilde{y}}\right]+\sigma^2, $$ -that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \). +

    that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \).

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs038.html b/doc/pub/week37/html/._week37-bs038.html index 6797fada1..34db4de1c 100644 --- a/doc/pub/week37/html/._week37-bs038.html +++ b/doc/pub/week37/html/._week37-bs038.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    A way to Read the Bias-Variance Tradeoff

    -

    -



    +

    +
    +

    +
    +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs039.html b/doc/pub/week37/html/._week37-bs039.html index c1caf475b..948e27b74 100644 --- a/doc/pub/week37/html/._week37-bs039.html +++ b/doc/pub/week37/html/._week37-bs039.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Example code for Bias-Variance tradeoff

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -336,8 +328,22 @@ plt.scatter(x_test, y_test, label.scatter(x_test, np.mean(y_pred, axis=1), label='Pred')
     plt.legend()
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs040.html b/doc/pub/week37/html/._week37-bs040.html index 8dfe88d6e..4007d3fa9 100644 --- a/doc/pub/week37/html/._week37-bs040.html +++ b/doc/pub/week37/html/._week37-bs040.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Understanding what happens

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -328,8 +320,22 @@ plt.plot(polydegree, bias, label.plot(polydegree, variance, label='Variance')
     plt.legend()
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs041.html b/doc/pub/week37/html/._week37-bs041.html index 037ed693a..98989f4c1 100644 --- a/doc/pub/week37/html/._week37-bs041.html +++ b/doc/pub/week37/html/._week37-bs041.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Summing up

    -

    -The bias-variance tradeoff summarizes the fundamental tension in +

    The bias-variance tradeoff summarizes the fundamental tension in machine learning, particularly supervised learning, between the complexity of a model and the amount of training data needed to train it. Since data is often limited, in practice it is often useful to use a less-complex model with higher bias, that is a model whose asymptotic performance is worse than another model because it is easier to train and less sensitive to sampling noise arising from having a -finite-sized training dataset (smaller variance). +finite-sized training dataset (smaller variance). +

    -

    -The above equations tell us that in +

    The above equations tell us that in order to minimize the expected test error, we need to select a statistical learning method that simultaneously achieves low variance and low bias. Note that variance is inherently a nonnegative quantity, and squared bias is also nonnegative. Hence, we see that the expected test MSE can never lie below \( Var(\epsilon) \), the irreducible error. +

    -

    -What do we mean by the variance and bias of a statistical learning +

    What do we mean by the variance and bias of a statistical learning method? The variance refers to the amount by which our model would change if we estimated it using a different training data set. Since the training data are used to fit the statistical learning method, different @@ -308,11 +295,10 @@ estimate for our model should not vary too much between training sets. However, if a method has high variance then small changes in the training data can result in large changes in the model. In general, more flexible statistical methods have higher variance. +

    -

    -You may also find this recent article of interest. +

    You may also find this recent article of interest.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs042.html b/doc/pub/week37/html/._week37-bs042.html index 62cf0a71f..93c733270 100644 --- a/doc/pub/week37/html/._week37-bs042.html +++ b/doc/pub/week37/html/._week37-bs042.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Another Example from Scikit-Learn's Repository

    -

    -

    """
    +
    +
    +
    +
    +
    +
    """
     ============================
     Underfitting vs. Overfitting
     ============================
    @@ -353,8 +345,22 @@ plt.figure(figsize.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
             degrees[i], -scores.mean(), scores.std()))
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs043.html b/doc/pub/week37/html/._week37-bs043.html index c4d4344aa..92af9f171 100644 --- a/doc/pub/week37/html/._week37-bs043.html +++ b/doc/pub/week37/html/._week37-bs043.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Various steps in cross-validation

    -

    -When the repetitive splitting of the data set is done randomly, +

    When the repetitive splitting of the data set is done randomly, samples may accidently end up in a fast majority of the splits in either training or test set. Such samples may have an unbalanced influence on either model building or prediction evaluation. To avoid @@ -294,9 +281,9 @@ warrants a balanced representation of each sample in both training and test set over the splits. Still the division into the \( k \) subsets involves a degree of randomness. This may be fully excluded when choosing \( k=n \). This particular case is referred to as leave-one-out -cross-validation (LOOCV). +cross-validation (LOOCV). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs044.html b/doc/pub/week37/html/._week37-bs044.html index bf3530e9e..25899c0f8 100644 --- a/doc/pub/week37/html/._week37-bs044.html +++ b/doc/pub/week37/html/._week37-bs044.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    How to set up the cross-validation for Ridge and/or Lasso

    - $$ \begin{align*} \boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T} @@ -300,14 +287,13 @@ $$
  • Repeat the first three steps such that each sample plays the role of the test set once.
  • Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
  • - $$ \begin{align*} \frac{1}{n} \sum_{i = 1}^n \log\{L[y_i, \mathbf{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\}. \end{align*} $$ -

    +

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs045.html b/doc/pub/week37/html/._week37-bs045.html index 6956ce029..8c1d51079 100644 --- a/doc/pub/week37/html/._week37-bs045.html +++ b/doc/pub/week37/html/._week37-bs045.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Cross-validation in brief

    -

    -For the various values of \( k \) +

    For the various values of \( k \)

    1. shuffle the dataset randomly.
    2. Split the dataset into \( k \) groups.
    3. For each unique group: -
      1. Decide which group to use as set for test data
      2. Take the remaining groups as a training data set
      3. Fit a model on the training set and evaluate it on the test set
      4. Retain the evaluation score and discard the model
      -
    4. Summarize the model using the sample of model evaluation scores
    -

    -
    - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs046.html b/doc/pub/week37/html/._week37-bs046.html index 8fcf6d83a..48d02a96a 100644 --- a/doc/pub/week37/html/._week37-bs046.html +++ b/doc/pub/week37/html/._week37-bs046.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    Code Example for Cross-validation and \( k \)-fold Cross-validation

    -

    -The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial. -

    +

    The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial.

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import KFold
     from sklearn.linear_model import Ridge
    @@ -374,8 +365,22 @@ plt.ylabel('
     plt.legend()
     
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs047.html b/doc/pub/week37/html/._week37-bs047.html index ea91f3364..ee7a0b53f 100644 --- a/doc/pub/week37/html/._week37-bs047.html +++ b/doc/pub/week37/html/._week37-bs047.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    More examples on bootstrap and cross-validation and errors

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -361,11 +353,23 @@ plt.xlabel('
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    -Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones. +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.

    -

    - - - -
    - - - diff --git a/doc/pub/week37/html/._week37-bs048.html b/doc/pub/week37/html/._week37-bs048.html index 6c3d97210..ac4bff276 100644 --- a/doc/pub/week37/html/._week37-bs048.html +++ b/doc/pub/week37/html/._week37-bs048.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - -

    The same example but now with cross-validation

    -

    -In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error. -

    +

    In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -352,8 +343,20 @@ plt.xlabel('
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -372,25 +375,18 @@ plt.show()

  • 49
  • - - - -
    - - - diff --git a/doc/pub/week37/html/week37-bs.html b/doc/pub/week37/html/week37-bs.html index 2ae1b501d..8f20641eb 100644 --- a/doc/pub/week37/html/week37-bs.html +++ b/doc/pub/week37/html/week37-bs.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - + - - - -
    -

     

     

     

    - - - -
    -

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    +
    +

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    +
    -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Aug 23, 2022

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Sep 28, 2021

    -
    -

    Read »

    @@ -325,25 +313,18 @@ MathJax.Hub.Config({
  • »
  • -
    - - -
    - © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week37/html/week37-reveal.html b/doc/pub/week37/html/week37-reveal.html index a88e39b74..07364e98b 100644 --- a/doc/pub/week37/html/week37-reveal.html +++ b/doc/pub/week37/html/week37-reveal.html @@ -1,18 +1,17 @@ + - + + - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - - - - - - @@ -55,36 +54,81 @@ document.getElementsByTagName( 'head' )[0].appendChild( link ); - - - +
    +

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    +
    - - -

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    - -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Aug 23, 2022

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Sep 28, 2021

    -
    -











    -

    Plans for week 37

    - -Recommended Reading: - +

    Recommended Reading:

    1. Lectures on Resampling methods (these lectures)
    2. Bishop 1.3 (cross-validation) and 3.2 (bias-variance tradeoff)
    3. Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap). This chapter is better than Bishop's on these topics. Goodfellow et al discuss this in a superficial way in sections 5.2-5.5.
    +









    +

    Thursday September 15, Summary of Ridge and Lasso Regression and start Resampling methods











    - -

    Thursday September 16, Summary of Ridge and Lasso Regression and start Resampling methods

    - -

    -









    -

    Deriving OLS from a probability distribution

    -

    -Our basic assumption when we derived the OLS equations was to assume +

    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 +

    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 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} \). +

    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 +

    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 +

    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} \). +

    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} \). +

    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 +

    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. +data is the most probable. +

    -

    -We will assume here that our events are given by the above Gaussian +

    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 +

    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 +

    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 +

    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 +

    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 +

    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 \) +

    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}! $$ -

    -









    +









    Bayes' Theorem

    -

    -If we combine the conditional probability with the marginal probability and the standard product rule, we have +

    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 +

    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 \). +

    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 +

    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. +

    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.

    -











    -

    Test Function for what happens with OLS, Ridge and Lasso

    -

    -We will play around with a study of the values for the optimal +

    We will play around with a study of the values for the optimal parameters \( \boldsymbol{\beta} \) using OLS, Ridge and Lasso regression. For OLS, you will notice as function of the noise and polynomial degree, that the parameters \( \beta \) will fluctuate from order to order in the polynomial fit and that for larger and larger polynomial degrees of freedom, the parameters will tend to increase in value for OLS. +

    -

    -For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one. +

    For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one.

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import train_test_split
     from sklearn import linear_model
    @@ -508,29 +477,39 @@ plt.xlabel('log10(lambda)')
     plt.ylabel('MSE')
     plt.legend()
     plt.show()
    -
    -

    -How can we understand this? +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    How can we understand this?

    -











    -

    Rerunning the above code

    -

    -Let us write out the values of the coefficients \( \beta_i \) as functions +

    Let us write out the values of the coefficients \( \beta_i \) as functions of the polynomial degree and noise. We will focus only on the Ridge results and some few selected values of the hyperparameter \( \lambda \). +

    -

    -If we don't include any noise and run this code for different values +

    If we don't include any noise and run this code for different values of the polynomial degree, we notice that the results for \( \beta_i \) do not show great changes from one order to the next. This is an indication that for higher polynomial orders, our parameters become less important. +

    -

    -If we however add noise, what happens is that the polynomial fit is +

    If we however add noise, what happens is that the polynomial fit is trying to adjust the fit to traverse in the best possible way all data points. This can lead to large fluctuations in the parameters \( \beta_i \) as functions of polynomial order. It will also be reflected @@ -538,11 +517,16 @@ in a larger value of the variance of each parameter \( \beta_i \). What Ridge regression (and Lasso as well) are doing then is to try to quench the fluctuations in the parameters of \( \beta_i \) which have a large variance (normally for higher orders in the polynomial). +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     import matplotlib.pyplot as plt
    @@ -580,143 +564,137 @@ lambdas = np.logspace(-3, 'beta']
         display(BetaValues)    
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Invoking Bayes' theorem

    -

    -Using Bayes' theorem we can gain a better intuition about 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) +

    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 +

    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 +

    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) +

    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} \)! +

    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 +

    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 +

    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) +

    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 +

    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 +

    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? +

    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 +

    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) +

    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 +

    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 +

    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, $$ -which is our Lasso cost function! +

    which is our Lasso cost function!

    -











    -

    Why resampling methods

    -

    -Before we proceed, we need to rethink what we have been doing. In our +

    Before we proceed, we need to rethink what we have been doing. In our eager to fit the data, we have omitted several important elements in our regression analysis. In what follows we will - +

    1. look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff
    2. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more
    +

    and discuss how to select a given model (one of the difficult parts in machine learning).

    -and discuss how to select a given model (one of the difficult parts in machine learning). - -











    -

    Resampling methods

    -Resampling methods are an indispensable tool in modern +

    Resampling methods are an indispensable tool in modern statistics. They involve repeatedly drawing samples from a training set and refitting a model of interest on each sample in order to obtain additional information about the fitted model. For example, in @@ -726,32 +704,26 @@ regression to each new sample, and then examine the extent to which the resulting fits differ. Such an approach may allow us to obtain information that would not be available from fitting the model only once using the original training sample. +

    -

    -Two resampling methods are often used in Machine Learning analyses, - +

    Two resampling methods are often used in Machine Learning analyses,

    1. The bootstrap method
    2. and Cross-Validation
    - -In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular -cross-validation and the bootstrap method. - - +

    In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular +cross-validation and the bootstrap method. +

    -











    -

    Resampling approaches can be computationally expensive

    -

    -Resampling approaches can be computationally expensive, because they +

    Resampling approaches can be computationally expensive, because they involve fitting the same statistical method multiple times using different subsets of the training data. However, due to recent advances in computing power, the computational requirements of @@ -766,14 +738,11 @@ of flexibility. The process of evaluating a model’s performance is known as model assessment, whereas the process of selecting the proper level of flexibility for a model is known as model selection. The bootstrap is widely used. - - +

    -











    -

    Why resampling methods ?

    Statistical analysis @@ -785,11 +754,9 @@ bootstrap is widely used.
  • As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.
  • + - -











    -

    Statistical analysis

    @@ -797,97 +764,90 @@ bootstrap is widely used.
    + - -











    -

    Resampling methods

    -

    -With all these analytical equations for both the OLS and Ridge +

    With all these analytical equations for both the OLS and Ridge regression, we will now outline how to assess a given model. This will lead to a discussion of the so-called bias-variance tradeoff (see below) and so-called resampling methods. +

    -

    -One of the quantities we have discussed as a way to measure errors is +

    One of the quantities we have discussed as a way to measure errors is the mean-squared error (MSE), mainly used for fitting of continuous functions. Another choice is the absolute error. +

    -

    -In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, +

    In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, we discuss the - +

    1. prediction error or simply the test error \( \mathrm{Err_{Test}} \), where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the
    2. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    - -As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. +

    As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. For a certain level of complexity the test error will reach minimum, before starting to increase again. The training error reaches a saturation. +

    -











    -

    Resampling methods: Jackknife and Bootstrap

    -

    -Two famous -resampling methods are the independent bootstrap and the jackknife. +

    Two famous +resampling methods are the independent bootstrap and the jackknife. +

    -

    -The jackknife is a special case of the independent bootstrap. Still, the jackknife was made +

    The jackknife is a special case of the independent bootstrap. Still, the jackknife was made popular prior to the independent bootstrap. And as the popularity of the independent bootstrap soared, new variants, such as the dependent bootstrap have also been developed.. +

    -

    -The Jackknife and independent bootstrap work for +

    The Jackknife and independent bootstrap work for independent, identically distributed random variables. If these conditions are not satisfied, the methods will fail. Yet, it should be said that if the data are independent, identically distributed, and we only want to estimate the variance of \( \overline{X} \) (which often is the case), then there is no -need for bootstrapping. +need for bootstrapping. +

    -











    -

    Resampling methods: Jackknife

    -

    -The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). +

    The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). The jackknife is a resampling method where we systematically leave out one observation from the vector of observed values \( \boldsymbol{x} = (x_1,x_2,\cdots,X_n) \). Let \( \boldsymbol{x}_i \) denote the vector +

    $$ \boldsymbol{x}_i = (x_1,x_2,\cdots,x_{i-1},x_{i+1},\cdots,x_n), $$ -

    -which equals the vector \( \boldsymbol{x} \) with the exception that observation +

    which equals the vector \( \boldsymbol{x} \) with the exception that observation number \( i \) is left out. Using this notation, define \( \widehat{\beta}_i \) to be the estimator -\( \widehat{\beta} \) computed using \( \vec{X}_i \). +\( \widehat{\beta} \) computed using \( \vec{X}_i \). +

    -











    -

    Jackknife code example

    -

    -

    from numpy import *
    +
    +
    +
    +
    +
    +
    from numpy import *
     from numpy.random import randint, randn
     from time import time
     
    @@ -900,7 +860,7 @@ number \( i \) is left out. Using this notation, define
         # analysis                                                                                                                                                                     
         print("Runtime: %g sec" % (time()-t0)); print("Jackknife Statistics :")
         print("original           bias      std. error")
    -    print("%8g %14g %15g" % (stat(data),(n-1)*mean(t)/n, (n*var(t))**.5))
    +    print("%8g %14g %15g" % (stat(data),(n-1)*mean(t)/n, (n*var(t))**.5))
     
         return t
     
    @@ -915,19 +875,32 @@ datapoints = 10000
     x = mu + sigma*random.randn(datapoints)
     # jackknife returns the data sample                                                                                                                                                
     t = jackknife(x, stat)
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Resampling methods: Bootstrap

    -Bootstrapping is a non-parametric approach to statistical inference +

    Bootstrapping is a non-parametric approach to statistical inference that substitutes computation for more traditional distributional assumptions and asymptotic results. Bootstrapping offers a number of advantages: - +

    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small.
    3. @@ -937,76 +910,68 @@ advantages:
    -

    -The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani. +

    The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani.

    -

    -Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem. +

    Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem.

    -











    -

    The Central Limit Theorem

    -

    -Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) +

    Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) of averages \( \mathbb{E}[x_i] \). Each mean value \( \mathbb{E}[x_i] \) is viewed as the average of a specific measurement, e.g., throwing dice 100 times and then taking the average value, or producing a certain amount of random numbers. For notational ease, we set \( \mathbb{E}[x_i]=x_i \) in the discussion which follows. We do the same for \( \mathbb{E}[z]=z \). +

    -

    -If we compute the mean \( z \) of \( m \) such mean values \( x_i \) +

    If we compute the mean \( z \) of \( m \) such mean values \( x_i \)

    $$ z=\frac{x_1+x_2+\dots+x_m}{m}, $$ -the question we pose is which is the PDF of the new variable \( z \). +

    the question we pose is which is the PDF of the new variable \( z \).

    -











    -

    Finding the Limit

    -

    -The probability of obtaining an average value \( z \) is the product of the +

    The probability of obtaining an average value \( z \) is the product of the probabilities of obtaining arbitrary individual mean values \( x_i \), but with the constraint that the average is \( z \). We can express this through the following expression +

    $$ \tilde{p}(z)=\int dx_1p(x_1)\int dx_2p(x_2)\dots\int dx_mp(x_m) \delta(z-\frac{x_1+x_2+\dots+x_m}{m}), $$ -where the \( \delta \)-function enbodies the constraint that the mean is \( z \). +

    where the \( \delta \)-function enbodies the constraint that the mean is \( z \). All measurements that lead to each individual \( x_i \) are expected to be independent, which in turn means that we can express \( \tilde{p} \) as the product of individual \( p(x_i) \). The independence assumption is important in the derivation of the central limit theorem. +

    -











    -

    Rewriting the \( \delta \)-function

    -

    -If we use the integral expression for the \( \delta \)-function +

    If we use the integral expression for the \( \delta \)-function

    $$ \delta(z-\frac{x_1+x_2+\dots+x_m}{m})=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\frac{x_1+x_2+\dots+x_m}{m})\right)}, $$ -and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value +

    and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value we arrive at +

    $$ \tilde{p}(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\mu)\right)}\left[\int_{-\infty}^{\infty} dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m, $$ -with the integral over \( x \) resulting in +

    with the integral over \( x \) resulting in

    $$ \int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}= @@ -1014,140 +979,130 @@ $$ \left[1+\frac{iq(\mu-x)}{m}-\frac{q^2(\mu-x)^2}{2m^2}+\dots\right]. $$ -

    -









    +









    Identifying Terms

    -

    -The second term on the rhs disappears since this is just the mean and +

    The second term on the rhs disappears since this is just the mean and employing the definition of \( \sigma^2 \) we have +

    $$ \int_{-\infty}^{\infty}dxp(x)e^{\left(iq(\mu-x)/m\right)}= 1-\frac{q^2\sigma^2}{2m^2}+\dots, $$ -resulting in +

    resulting in

    $$ \left[\int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m\approx \left[1-\frac{q^2\sigma^2}{2m^2}+\dots \right]^m, $$ -and in the limit \( m\rightarrow \infty \) we obtain +

    and in the limit \( m\rightarrow \infty \) we obtain

    $$ \tilde{p}(z)=\frac{1}{\sqrt{2\pi}(\sigma/\sqrt{m})} \exp{\left(-\frac{(z-\mu)^2}{2(\sigma/\sqrt{m})^2}\right)}, $$ -which is the normal distribution with variance +

    which is the normal distribution with variance \( \sigma^2_m=\sigma^2/m \), where \( \sigma \) is the variance of the PDF \( p(x) \) -and \( \mu \) is also the mean of the PDF \( p(x) \). +and \( \mu \) is also the mean of the PDF \( p(x) \). +

    -











    -

    Wrapping it up

    -

    -Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of +

    Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of the average of \( m \) random values corresponding to a PDF \( p(x) \) is a normal distribution whose mean is the mean value of the PDF \( p(x) \) and whose variance is the variance of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \). +

    -

    -The central limit theorem leads to the well-known expression for the +

    The central limit theorem leads to the well-known expression for the standard deviation, given by +

    $$ \sigma_m= \frac{\sigma}{\sqrt{m}}. $$ -

    -The latter is true only if the average value is known exactly. This is obtained in the limit +

    The latter is true only if the average value is known exactly. This is obtained in the limit \( m\rightarrow \infty \) only. Because the mean and the variance are measured quantities we obtain the familiar expression in statistics (the so-called Bessel correction) +

    $$ \sigma_m\approx \frac{\sigma}{\sqrt{m-1}}. $$ -

    -In many cases however the above estimate for the standard deviation, +

    In many cases however the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. Keep in mind that we have assumed that the variables \( x \) are independent and identically distributed. This is obviously not always the case. For example, the random numbers (or better pseudorandom numbers) we generate in various calculations do always exhibit some correlations. +

    -

    -The theorem is satisfied by a large class of PDFs. Note however that for a +

    The theorem is satisfied by a large class of PDFs. Note however that for a finite \( m \), it is not always possible to find a closed form /analytic expression for \( \tilde{p}(x) \). +

    -











    -

    Confidence Intervals

    -

    -Confidence intervals are used in statistics and represent a type of estimate +

    Confidence intervals are used in statistics and represent a type of estimate computed from the observed data. This gives a range of values for an unknown parameter such as the parameters \( \boldsymbol{\beta} \) from linear regression. +

    -

    -With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found +

    With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found \( \mathbb{E}(\boldsymbol{\beta}) = \boldsymbol{\beta} \), which means that the estimator of the regression parameters is unbiased. +

    -

    -We found also that the variance of the estimate of the \( j \)-th regression coefficient is +

    We found also that the variance of the estimate of the \( j \)-th regression coefficient is \( \boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} \). +

    -

    -This quantity will be used to +

    This quantity will be used to construct a confidence interval for the estimates. +

    -











    -

    Standard Approach based on the Normal Distribution

    -

    -We will assume that the parameters \( \beta \) follow a normal +

    We will assume that the parameters \( \beta \) follow a normal distribution. We can then define the confidence interval. Here we will be using as shorthands \( \mu_{\beta} \) for the above mean value and \( \sigma_{\beta} \) for the standard deviation. We have then a confidence interval +

    $$ \left(\mu_{\beta}\pm \frac{z\sigma_{\beta}}{\sqrt{n}}\right), $$ -

    -where \( z \) defines the level of certainty (or confidence). For a normal +

    where \( z \) defines the level of certainty (or confidence). For a normal distribution typical parameters are \( z=2.576 \) which corresponds to a confidence of \( 99\% \) while \( z=1.96 \) corresponds to a confidence of \( 95\% \). A confidence level of \( 95\% \) is commonly used and it is normally referred to as a two-sigmas confidence level, that is we approximate \( z\approx 2 \). +

    -

    -For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications +

    For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications

    -

    -In this text you will also find an in-depth discussion of the -Bootstrap method, why it works and various theorems related to it. +

    In this text you will also find an in-depth discussion of the +Bootstrap method, why it works and various theorems related to it. +

    -











    -

    Resampling methods: Bootstrap background

    -

    -Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, +

    Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, \( \widehat{\beta} \) itself must be a random variable. Thus it has a pdf, call this function \( p(\boldsymbol{t}) \). The aim of the bootstrap is to estimate \( p(\boldsymbol{t}) \) by the relative frequency of @@ -1155,55 +1110,48 @@ estimate \( p(\boldsymbol{t}) \) by the relative frequency of in the place of \( p(\boldsymbol{t}) \). If the relative frequency closely resembles \( p(\vec{t}) \), then using numerics, it is straight forward to estimate all the interesting parameters of \( p(\boldsymbol{t}) \) using point -estimators. +estimators. +

    -











    -

    Resampling methods: More Bootstrap background

    -

    -In the case that \( \widehat{\beta} \) has +

    In the case that \( \widehat{\beta} \) has more than one component, and the components are independent, we use the same estimator on each component separately. If the probability density function of \( X_i \), \( p(x) \), had been known, then it would have been straightforward to do this by: - +

    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. Then using these numbers, we could compute a replica of \( \widehat{\beta} \) called \( \widehat{\beta}^* \).
    - -By repeated use of the above two points, many +

    By repeated use of the above two points, many estimates of \( \widehat{\beta} \) can be obtained. The idea is to use the relative frequency of \( \widehat{\beta}^* \) (think of a histogram) as an estimate of \( p(\boldsymbol{t}) \). +

    -











    -

    Resampling methods: Bootstrap approach

    -

    -But +

    But unless there is enough information available about the process that generated \( X_1,X_2,\cdots,X_n \), \( p(x) \) is in general unknown. Therefore, Efron in 1979 asked the question: What if we replace \( p(x) \) by the relative frequency of the observation \( X_i \)? +

    -

    -If we draw observations in accordance with +

    If we draw observations in accordance with the relative frequency of the observations, will we obtain the same result in some asymptotic sense? The answer is yes. +

    -











    -

    Resampling methods: Bootstrap steps

    -

    -The independent bootstrap works like this: +

    The independent bootstrap works like this:

    1. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    2. @@ -1211,8 +1159,7 @@ The independent bootstrap works like this:
    3. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\beta}^* \) by evaluating \( \widehat \beta \) under the observations \( \boldsymbol{x}^* \).
    4. Repeat this process \( k \) times.
    - -When you are done, you can draw a histogram of the relative frequency +

    When you are done, you can draw a histogram of the relative frequency of \( \widehat \beta^* \). This is your estimate of the probability distribution \( p(t) \). Using this probability distribution you can estimate any statistics thereof. In principle you never draw the @@ -1221,14 +1168,12 @@ you use the estimators corresponding to the statistic of interest. For example, if you are interested in estimating the variance of \( \widehat \beta \), apply the etsimator \( \widehat \sigma^2 \) to the values \( \widehat \beta^* \). +

    -











    -

    Code example for the Bootstrap method

    -

    -The following code starts with a Gaussian distribution with mean value +

    The following code starts with a Gaussian distribution with mean value \( \mu =100 \) and variance \( \sigma=15 \). We use this to generate the data used in the bootstrap analysis. The bootstrap analysis returns a data set after a given number of bootstrap operations (as many as we have @@ -1240,11 +1185,16 @@ centered around the mean value \( \mu=100 \) but with standard deviation this case the same as the number of original data points). The value of the standard deviation is what we expect from the central limit theorem. +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from time import time
     from scipy.stats import norm
     import matplotlib.pyplot as plt
    @@ -1270,18 +1220,33 @@ datapoints = 10000
     x = mu + sigma*np.random.randn(datapoints)
     # bootstrap returns the data sample                                    
     t = bootstrap(x, datapoints)
    -
    -

    -We see that our new variance and from that the standard deviation, agrees with the central limit theorem. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We see that our new variance and from that the standard deviation, agrees with the central limit theorem.

    -











    -

    Plotting the Histogram

    -

    -

    # the histogram of the bootstrapped data (normalized data if density = True)
    +
    +
    +
    +
    +
    +
    # the histogram of the bootstrapped data (normalized data if density = True)
     n, binsboot, patches = plt.hist(t, 50, density=True, facecolor='red', alpha=0.75)
     # add a 'best fit' line  
     y = norm.pdf(binsboot, np.mean(t), np.std(t))
    @@ -1290,89 +1255,101 @@ plt.xlabel('x')
     plt.ylabel('Probability')
     plt.grid(True)
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    The bias-variance tradeoff

    -

    -We will discuss the bias-variance tradeoff in the context of +

    We will discuss the bias-variance tradeoff in the context of continuous predictions such as regression. However, many of the intuitions and ideas discussed here also carry over to classification tasks. Consider a dataset \( \mathcal{D} \) consisting of the data -\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +

    -

    -Let us assume that the true data is generated from a noisy model +

    Let us assume that the true data is generated from a noisy model

    $$ \boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} $$ -

    -where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \). +

    where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \).

    -

    -In our derivation of the ordinary least squares method we defined then +

    In our derivation of the ordinary least squares method we defined then an approximation to the function \( f \) in terms of the parameters \( \boldsymbol{\beta} \) and the design matrix \( \boldsymbol{X} \) which embody our model, -that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +

    -

    -Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function +

    Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function

    $$ C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]. $$ -

    -We can rewrite this as +

    We can rewrite this as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2. $$ -

    -The three terms represent the square of the bias of the learning +

    The three terms represent the square of the bias of the learning method, which can be thought of as the error caused by the simplifying assumptions built into the method. The second term represents the variance of the chosen model and finally the last terms is variance of the error \( \boldsymbol{\epsilon} \). +

    -

    -To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). +

    To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). We use a more compact notation in terms of the expectation value +

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}})^2\right], $$ -and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get +

    and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}}+\mathbb{E}\left[\boldsymbol{\tilde{y}}\right]-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right], $$ -which, using the abovementioned expectation values can be rewritten as +

    which, using the abovementioned expectation values can be rewritten as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{y}-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\boldsymbol{\tilde{y}}\right]+\sigma^2, $$ -that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \). +

    that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \).

    -











    -

    A way to Read the Bias-Variance Tradeoff

    -

    -



    +

    +
    +

    +
    +

    -











    -

    Example code for Bias-Variance tradeoff

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -1426,15 +1403,32 @@ plt.scatter(x_test, y_test, label='Data points&
     plt.scatter(x_test, np.mean(y_pred, axis=1), label='Pred')
     plt.legend()
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Understanding what happens

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -1480,32 +1474,44 @@ plt.plot(polydegree, bias, label='bias''Variance')
     plt.legend()
     plt.show()
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Summing up

    -

    -The bias-variance tradeoff summarizes the fundamental tension in +

    The bias-variance tradeoff summarizes the fundamental tension in machine learning, particularly supervised learning, between the complexity of a model and the amount of training data needed to train it. Since data is often limited, in practice it is often useful to use a less-complex model with higher bias, that is a model whose asymptotic performance is worse than another model because it is easier to train and less sensitive to sampling noise arising from having a -finite-sized training dataset (smaller variance). +finite-sized training dataset (smaller variance). +

    -

    -The above equations tell us that in +

    The above equations tell us that in order to minimize the expected test error, we need to select a statistical learning method that simultaneously achieves low variance and low bias. Note that variance is inherently a nonnegative quantity, and squared bias is also nonnegative. Hence, we see that the expected test MSE can never lie below \( Var(\epsilon) \), the irreducible error. +

    -

    -What do we mean by the variance and bias of a statistical learning +

    What do we mean by the variance and bias of a statistical learning method? The variance refers to the amount by which our model would change if we estimated it using a different training data set. Since the training data are used to fit the statistical learning method, different @@ -1514,18 +1520,20 @@ estimate for our model should not vary too much between training sets. However, if a method has high variance then small changes in the training data can result in large changes in the model. In general, more flexible statistical methods have higher variance. +

    -

    -You may also find this recent article of interest. +

    You may also find this recent article of interest.

    -











    -

    Another Example from Scikit-Learn's Repository

    -

    -

    """
    +
    +
    +
    +
    +
    +
    """
     ============================
     Underfitting vs. Overfitting
     ============================
    @@ -1596,14 +1604,26 @@ plt.figure(figsize=(14, "Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
             degrees[i], -scores.mean(), scores.std()))
     plt.show()
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Various steps in cross-validation

    -

    -When the repetitive splitting of the data set is done randomly, +

    When the repetitive splitting of the data set is done randomly, samples may accidently end up in a fast majority of the splits in either training or test set. Such samples may have an unbalanced influence on either model building or prediction evaluation. To avoid @@ -1616,11 +1636,10 @@ warrants a balanced representation of each sample in both training and test set over the splits. Still the division into the \( k \) subsets involves a degree of randomness. This may be fully excluded when choosing \( k=n \). This particular case is referred to as leave-one-out -cross-validation (LOOCV). +cross-validation (LOOCV). +

    -

    -

    How to set up the cross-validation for Ridge and/or Lasso

    - $$ \begin{align*} \boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T} @@ -1643,46 +1661,42 @@ $$
  • Repeat the first three steps such that each sample plays the role of the test set once.
  • Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
  • - $$ \begin{align*} \frac{1}{n} \sum_{i = 1}^n \log\{L[y_i, \mathbf{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\}. \end{align*} $$ -

    -









    +









    Cross-validation in brief

    -

    -For the various values of \( k \) +

    For the various values of \( k \)

    1. shuffle the dataset randomly.
    2. Split the dataset into \( k \) groups.
    3. For each unique group: -
      1. Decide which group to use as set for test data
      2. Take the remaining groups as a training data set
      3. Fit a model on the training set and evaluate it on the test set
      4. Retain the evaluation score and discard the model
      -
    4. Summarize the model using the sample of model evaluation scores
    -









    -

    Code Example for Cross-validation and \( k \)-fold Cross-validation

    -

    -The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial. -

    +

    The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial.

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import KFold
     from sklearn.linear_model import Ridge
    @@ -1771,16 +1785,33 @@ plt.ylabel('mse')
     plt.legend()
     
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    More examples on bootstrap and cross-validation and errors

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -1858,21 +1889,35 @@ plt.xlabel('Polynomial degree')
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    -Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.

    -

    -

    The same example but now with cross-validation

    -

    -In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error. -

    +

    In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -1939,18 +1984,25 @@ plt.xlabel('Polynomial degree')
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + - -
    - © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week37/html/week37.html b/doc/pub/week37/html/week37.html index 148d17190..24e59b9fb 100644 --- a/doc/pub/week37/html/week37.html +++ b/doc/pub/week37/html/week37.html @@ -1,6 +1,7 @@ @@ -8,29 +9,97 @@ Automatically generated HTML file from DocOnce source - Week 37: Summary of Ridge and Lasso Regression and Resampling Methods - - - - +
    +

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    +
    - - -

    Week 37: Summary of Ridge and Lasso Regression and Resampling Methods

    - -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Aug 23, 2022

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Sep 28, 2021

    -
    -











    -

    Plans for week 37

    - -Recommended Reading: - +

    Recommended Reading:

    1. Lectures on Resampling methods (these lectures)
    2. Bishop 1.3 (cross-validation) and 3.2 (bias-variance tradeoff)
    3. Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap). This chapter is better than Bishop's on these topics. Goodfellow et al discuss this in a superficial way in sections 5.2-5.5.
    +









    +

    Thursday September 15, Summary of Ridge and Lasso Regression and start Resampling methods











    - -

    Thursday September 16, Summary of Ridge and Lasso Regression and start Resampling methods

    - -

    -









    -

    Deriving OLS from a probability distribution

    -

    -Our basic assumption when we derived the OLS equations was to assume +

    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 +

    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 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} \). +

    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 +

    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 +

    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} \). +

    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} \). +

    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 +

    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. +data is the most probable. +

    -

    -We will assume here that our events are given by the above Gaussian +

    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 +

    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 +

    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 +

    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 +

    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 +

    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 \) +

    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}! $$ -

    -









    +









    Bayes' Theorem

    -

    -If we combine the conditional probability with the marginal probability and the standard product rule, we have +

    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 +

    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 \). +

    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 +

    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. +

    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.

    -











    -

    Test Function for what happens with OLS, Ridge and Lasso

    -

    -We will play around with a study of the values for the optimal +

    We will play around with a study of the values for the optimal parameters \( \boldsymbol{\beta} \) using OLS, Ridge and Lasso regression. For OLS, you will notice as function of the noise and polynomial degree, that the parameters \( \beta \) will fluctuate from order to order in the polynomial fit and that for larger and larger polynomial degrees of freedom, the parameters will tend to increase in value for OLS. +

    -

    -For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one. +

    For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one.

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import train_test_split
     from sklearn import linear_model
    @@ -513,29 +554,39 @@ plt.xlabel('
     plt.ylabel('MSE')
     plt.legend()
     plt.show()
    -
    -

    -How can we understand this? +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    How can we understand this?

    -











    -

    Rerunning the above code

    -

    -Let us write out the values of the coefficients \( \beta_i \) as functions +

    Let us write out the values of the coefficients \( \beta_i \) as functions of the polynomial degree and noise. We will focus only on the Ridge results and some few selected values of the hyperparameter \( \lambda \). +

    -

    -If we don't include any noise and run this code for different values +

    If we don't include any noise and run this code for different values of the polynomial degree, we notice that the results for \( \beta_i \) do not show great changes from one order to the next. This is an indication that for higher polynomial orders, our parameters become less important. +

    -

    -If we however add noise, what happens is that the polynomial fit is +

    If we however add noise, what happens is that the polynomial fit is trying to adjust the fit to traverse in the best possible way all data points. This can lead to large fluctuations in the parameters \( \beta_i \) as functions of polynomial order. It will also be reflected @@ -543,11 +594,16 @@ in a larger value of the variance of each parameter \( \beta_i \). What Ridge regression (and Lasso as well) are doing then is to try to quench the fluctuations in the parameters of \( \beta_i \) which have a large variance (normally for higher orders in the polynomial). +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     import matplotlib.pyplot as plt
    @@ -585,143 +641,137 @@ lambdas = np.= pd.DataFrame(Coeffs)
         BetaValues.columns = ['beta']
         display(BetaValues)    
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Invoking Bayes' theorem

    -

    -Using Bayes' theorem we can gain a better intuition about 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) +

    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 +

    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 +

    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) +

    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} \)! +

    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 +

    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 +

    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) +

    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 +

    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 +

    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? +

    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 +

    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) +

    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 +

    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 +

    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, $$ -which is our Lasso cost function! +

    which is our Lasso cost function!

    -











    -

    Why resampling methods

    -

    -Before we proceed, we need to rethink what we have been doing. In our +

    Before we proceed, we need to rethink what we have been doing. In our eager to fit the data, we have omitted several important elements in our regression analysis. In what follows we will - +

    1. look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff
    2. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more
    +

    and discuss how to select a given model (one of the difficult parts in machine learning).

    -and discuss how to select a given model (one of the difficult parts in machine learning). - -











    -

    Resampling methods

    -Resampling methods are an indispensable tool in modern +

    Resampling methods are an indispensable tool in modern statistics. They involve repeatedly drawing samples from a training set and refitting a model of interest on each sample in order to obtain additional information about the fitted model. For example, in @@ -731,32 +781,26 @@ regression to each new sample, and then examine the extent to which the resulting fits differ. Such an approach may allow us to obtain information that would not be available from fitting the model only once using the original training sample. +

    -

    -Two resampling methods are often used in Machine Learning analyses, - +

    Two resampling methods are often used in Machine Learning analyses,

    1. The bootstrap method
    2. and Cross-Validation
    - -In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular -cross-validation and the bootstrap method. - - +

    In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular +cross-validation and the bootstrap method. +

    -











    -

    Resampling approaches can be computationally expensive

    -

    -Resampling approaches can be computationally expensive, because they +

    Resampling approaches can be computationally expensive, because they involve fitting the same statistical method multiple times using different subsets of the training data. However, due to recent advances in computing power, the computational requirements of @@ -771,14 +815,11 @@ of flexibility. The process of evaluating a model’s performance is known as model assessment, whereas the process of selecting the proper level of flexibility for a model is known as model selection. The bootstrap is widely used. - - +

    -











    -

    Why resampling methods ?

    Statistical analysis @@ -790,11 +831,9 @@ bootstrap is widely used.
  • As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.
  • + - -











    -

    Statistical analysis

    @@ -802,97 +841,90 @@ bootstrap is widely used.
    + - -











    -

    Resampling methods

    -

    -With all these analytical equations for both the OLS and Ridge +

    With all these analytical equations for both the OLS and Ridge regression, we will now outline how to assess a given model. This will lead to a discussion of the so-called bias-variance tradeoff (see below) and so-called resampling methods. +

    -

    -One of the quantities we have discussed as a way to measure errors is +

    One of the quantities we have discussed as a way to measure errors is the mean-squared error (MSE), mainly used for fitting of continuous functions. Another choice is the absolute error. +

    -

    -In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, +

    In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, we discuss the - +

    1. prediction error or simply the test error \( \mathrm{Err_{Test}} \), where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the
    2. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    - -As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. +

    As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. For a certain level of complexity the test error will reach minimum, before starting to increase again. The training error reaches a saturation. +

    -











    -

    Resampling methods: Jackknife and Bootstrap

    -

    -Two famous -resampling methods are the independent bootstrap and the jackknife. +

    Two famous +resampling methods are the independent bootstrap and the jackknife. +

    -

    -The jackknife is a special case of the independent bootstrap. Still, the jackknife was made +

    The jackknife is a special case of the independent bootstrap. Still, the jackknife was made popular prior to the independent bootstrap. And as the popularity of the independent bootstrap soared, new variants, such as the dependent bootstrap have also been developed.. +

    -

    -The Jackknife and independent bootstrap work for +

    The Jackknife and independent bootstrap work for independent, identically distributed random variables. If these conditions are not satisfied, the methods will fail. Yet, it should be said that if the data are independent, identically distributed, and we only want to estimate the variance of \( \overline{X} \) (which often is the case), then there is no -need for bootstrapping. +need for bootstrapping. +

    -











    -

    Resampling methods: Jackknife

    -

    -The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). +

    The Jackknife works by making many replicas of the estimator \( \widehat{\beta} \). The jackknife is a resampling method where we systematically leave out one observation from the vector of observed values \( \boldsymbol{x} = (x_1,x_2,\cdots,X_n) \). Let \( \boldsymbol{x}_i \) denote the vector +

    $$ \boldsymbol{x}_i = (x_1,x_2,\cdots,x_{i-1},x_{i+1},\cdots,x_n), $$ -

    -which equals the vector \( \boldsymbol{x} \) with the exception that observation +

    which equals the vector \( \boldsymbol{x} \) with the exception that observation number \( i \) is left out. Using this notation, define \( \widehat{\beta}_i \) to be the estimator -\( \widehat{\beta} \) computed using \( \vec{X}_i \). +\( \widehat{\beta} \) computed using \( \vec{X}_i \). +

    -











    -

    Jackknife code example

    -

    -

    from numpy import *
    +
    +
    +
    +
    +
    +
    from numpy import *
     from numpy.random import randint, randn
     from time import time
     
    @@ -920,19 +952,32 @@ datapoints = 10
     x = mu + sigma*random.randn(datapoints)
     # jackknife returns the data sample                                                                                                                                                
     t = jackknife(x, stat)
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Resampling methods: Bootstrap

    -Bootstrapping is a non-parametric approach to statistical inference +

    Bootstrapping is a non-parametric approach to statistical inference that substitutes computation for more traditional distributional assumptions and asymptotic results. Bootstrapping offers a number of advantages: - +

    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small.
    3. @@ -942,76 +987,68 @@ advantages:
    -

    -The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani. +

    The textbook by Davison on the Bootstrap Methods and their Applications provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by Efron and Tibshirani.

    -

    -Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem. +

    Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called central limit theorem.

    -











    -

    The Central Limit Theorem

    -

    -Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) +

    Suppose we have a PDF \( p(x) \) from which we generate a series \( N \) of averages \( \mathbb{E}[x_i] \). Each mean value \( \mathbb{E}[x_i] \) is viewed as the average of a specific measurement, e.g., throwing dice 100 times and then taking the average value, or producing a certain amount of random numbers. For notational ease, we set \( \mathbb{E}[x_i]=x_i \) in the discussion which follows. We do the same for \( \mathbb{E}[z]=z \). +

    -

    -If we compute the mean \( z \) of \( m \) such mean values \( x_i \) +

    If we compute the mean \( z \) of \( m \) such mean values \( x_i \)

    $$ z=\frac{x_1+x_2+\dots+x_m}{m}, $$ -the question we pose is which is the PDF of the new variable \( z \). +

    the question we pose is which is the PDF of the new variable \( z \).

    -











    -

    Finding the Limit

    -

    -The probability of obtaining an average value \( z \) is the product of the +

    The probability of obtaining an average value \( z \) is the product of the probabilities of obtaining arbitrary individual mean values \( x_i \), but with the constraint that the average is \( z \). We can express this through the following expression +

    $$ \tilde{p}(z)=\int dx_1p(x_1)\int dx_2p(x_2)\dots\int dx_mp(x_m) \delta(z-\frac{x_1+x_2+\dots+x_m}{m}), $$ -where the \( \delta \)-function enbodies the constraint that the mean is \( z \). +

    where the \( \delta \)-function enbodies the constraint that the mean is \( z \). All measurements that lead to each individual \( x_i \) are expected to be independent, which in turn means that we can express \( \tilde{p} \) as the product of individual \( p(x_i) \). The independence assumption is important in the derivation of the central limit theorem. +

    -











    -

    Rewriting the \( \delta \)-function

    -

    -If we use the integral expression for the \( \delta \)-function +

    If we use the integral expression for the \( \delta \)-function

    $$ \delta(z-\frac{x_1+x_2+\dots+x_m}{m})=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\frac{x_1+x_2+\dots+x_m}{m})\right)}, $$ -and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value +

    and inserting \( e^{i\mu q-i\mu q} \) where \( \mu \) is the mean value we arrive at +

    $$ \tilde{p}(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} dq\exp{\left(iq(z-\mu)\right)}\left[\int_{-\infty}^{\infty} dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m, $$ -with the integral over \( x \) resulting in +

    with the integral over \( x \) resulting in

    $$ \int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}= @@ -1019,140 +1056,130 @@ $$ \left[1+\frac{iq(\mu-x)}{m}-\frac{q^2(\mu-x)^2}{2m^2}+\dots\right]. $$ -

    -









    +









    Identifying Terms

    -

    -The second term on the rhs disappears since this is just the mean and +

    The second term on the rhs disappears since this is just the mean and employing the definition of \( \sigma^2 \) we have +

    $$ \int_{-\infty}^{\infty}dxp(x)e^{\left(iq(\mu-x)/m\right)}= 1-\frac{q^2\sigma^2}{2m^2}+\dots, $$ -resulting in +

    resulting in

    $$ \left[\int_{-\infty}^{\infty}dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m\approx \left[1-\frac{q^2\sigma^2}{2m^2}+\dots \right]^m, $$ -and in the limit \( m\rightarrow \infty \) we obtain +

    and in the limit \( m\rightarrow \infty \) we obtain

    $$ \tilde{p}(z)=\frac{1}{\sqrt{2\pi}(\sigma/\sqrt{m})} \exp{\left(-\frac{(z-\mu)^2}{2(\sigma/\sqrt{m})^2}\right)}, $$ -which is the normal distribution with variance +

    which is the normal distribution with variance \( \sigma^2_m=\sigma^2/m \), where \( \sigma \) is the variance of the PDF \( p(x) \) -and \( \mu \) is also the mean of the PDF \( p(x) \). +and \( \mu \) is also the mean of the PDF \( p(x) \). +

    -











    -

    Wrapping it up

    -

    -Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of +

    Thus, the central limit theorem states that the PDF \( \tilde{p}(z) \) of the average of \( m \) random values corresponding to a PDF \( p(x) \) is a normal distribution whose mean is the mean value of the PDF \( p(x) \) and whose variance is the variance of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \). +

    -

    -The central limit theorem leads to the well-known expression for the +

    The central limit theorem leads to the well-known expression for the standard deviation, given by +

    $$ \sigma_m= \frac{\sigma}{\sqrt{m}}. $$ -

    -The latter is true only if the average value is known exactly. This is obtained in the limit +

    The latter is true only if the average value is known exactly. This is obtained in the limit \( m\rightarrow \infty \) only. Because the mean and the variance are measured quantities we obtain the familiar expression in statistics (the so-called Bessel correction) +

    $$ \sigma_m\approx \frac{\sigma}{\sqrt{m-1}}. $$ -

    -In many cases however the above estimate for the standard deviation, +

    In many cases however the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. Keep in mind that we have assumed that the variables \( x \) are independent and identically distributed. This is obviously not always the case. For example, the random numbers (or better pseudorandom numbers) we generate in various calculations do always exhibit some correlations. +

    -

    -The theorem is satisfied by a large class of PDFs. Note however that for a +

    The theorem is satisfied by a large class of PDFs. Note however that for a finite \( m \), it is not always possible to find a closed form /analytic expression for \( \tilde{p}(x) \). +

    -











    -

    Confidence Intervals

    -

    -Confidence intervals are used in statistics and represent a type of estimate +

    Confidence intervals are used in statistics and represent a type of estimate computed from the observed data. This gives a range of values for an unknown parameter such as the parameters \( \boldsymbol{\beta} \) from linear regression. +

    -

    -With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found +

    With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we found \( \mathbb{E}(\boldsymbol{\beta}) = \boldsymbol{\beta} \), which means that the estimator of the regression parameters is unbiased. +

    -

    -We found also that the variance of the estimate of the \( j \)-th regression coefficient is +

    We found also that the variance of the estimate of the \( j \)-th regression coefficient is \( \boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} \). +

    -

    -This quantity will be used to +

    This quantity will be used to construct a confidence interval for the estimates. +

    -











    -

    Standard Approach based on the Normal Distribution

    -

    -We will assume that the parameters \( \beta \) follow a normal +

    We will assume that the parameters \( \beta \) follow a normal distribution. We can then define the confidence interval. Here we will be using as shorthands \( \mu_{\beta} \) for the above mean value and \( \sigma_{\beta} \) for the standard deviation. We have then a confidence interval +

    $$ \left(\mu_{\beta}\pm \frac{z\sigma_{\beta}}{\sqrt{n}}\right), $$ -

    -where \( z \) defines the level of certainty (or confidence). For a normal +

    where \( z \) defines the level of certainty (or confidence). For a normal distribution typical parameters are \( z=2.576 \) which corresponds to a confidence of \( 99\% \) while \( z=1.96 \) corresponds to a confidence of \( 95\% \). A confidence level of \( 95\% \) is commonly used and it is normally referred to as a two-sigmas confidence level, that is we approximate \( z\approx 2 \). +

    -

    -For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications +

    For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by Davison on the Bootstrap Methods and their Applications

    -

    -In this text you will also find an in-depth discussion of the -Bootstrap method, why it works and various theorems related to it. +

    In this text you will also find an in-depth discussion of the +Bootstrap method, why it works and various theorems related to it. +

    -











    -

    Resampling methods: Bootstrap background

    -

    -Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, +

    Since \( \widehat{\beta} = \widehat{\beta}(\boldsymbol{X}) \) is a function of random variables, \( \widehat{\beta} \) itself must be a random variable. Thus it has a pdf, call this function \( p(\boldsymbol{t}) \). The aim of the bootstrap is to estimate \( p(\boldsymbol{t}) \) by the relative frequency of @@ -1160,55 +1187,48 @@ estimate \( p(\boldsymbol{t}) \) by the relative frequency of in the place of \( p(\boldsymbol{t}) \). If the relative frequency closely resembles \( p(\vec{t}) \), then using numerics, it is straight forward to estimate all the interesting parameters of \( p(\boldsymbol{t}) \) using point -estimators. +estimators. +

    -











    -

    Resampling methods: More Bootstrap background

    -

    -In the case that \( \widehat{\beta} \) has +

    In the case that \( \widehat{\beta} \) has more than one component, and the components are independent, we use the same estimator on each component separately. If the probability density function of \( X_i \), \( p(x) \), had been known, then it would have been straightforward to do this by: - +

    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. Then using these numbers, we could compute a replica of \( \widehat{\beta} \) called \( \widehat{\beta}^* \).
    - -By repeated use of the above two points, many +

    By repeated use of the above two points, many estimates of \( \widehat{\beta} \) can be obtained. The idea is to use the relative frequency of \( \widehat{\beta}^* \) (think of a histogram) as an estimate of \( p(\boldsymbol{t}) \). +

    -











    -

    Resampling methods: Bootstrap approach

    -

    -But +

    But unless there is enough information available about the process that generated \( X_1,X_2,\cdots,X_n \), \( p(x) \) is in general unknown. Therefore, Efron in 1979 asked the question: What if we replace \( p(x) \) by the relative frequency of the observation \( X_i \)? +

    -

    -If we draw observations in accordance with +

    If we draw observations in accordance with the relative frequency of the observations, will we obtain the same result in some asymptotic sense? The answer is yes. +

    -











    -

    Resampling methods: Bootstrap steps

    -

    -The independent bootstrap works like this: +

    The independent bootstrap works like this:

    1. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    2. @@ -1216,8 +1236,7 @@ The independent bootstrap works like this:
    3. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\beta}^* \) by evaluating \( \widehat \beta \) under the observations \( \boldsymbol{x}^* \).
    4. Repeat this process \( k \) times.
    - -When you are done, you can draw a histogram of the relative frequency +

    When you are done, you can draw a histogram of the relative frequency of \( \widehat \beta^* \). This is your estimate of the probability distribution \( p(t) \). Using this probability distribution you can estimate any statistics thereof. In principle you never draw the @@ -1226,14 +1245,12 @@ you use the estimators corresponding to the statistic of interest. For example, if you are interested in estimating the variance of \( \widehat \beta \), apply the etsimator \( \widehat \sigma^2 \) to the values \( \widehat \beta^* \). +

    -











    -

    Code example for the Bootstrap method

    -

    -The following code starts with a Gaussian distribution with mean value +

    The following code starts with a Gaussian distribution with mean value \( \mu =100 \) and variance \( \sigma=15 \). We use this to generate the data used in the bootstrap analysis. The bootstrap analysis returns a data set after a given number of bootstrap operations (as many as we have @@ -1245,11 +1262,16 @@ centered around the mean value \( \mu=100 \) but with standard deviation this case the same as the number of original data points). The value of the standard deviation is what we expect from the central limit theorem. +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from time import time
     from scipy.stats import norm
     import matplotlib.pyplot as plt
    @@ -1275,18 +1297,33 @@ datapoints = 10
     x = mu + sigma*np.random.randn(datapoints)
     # bootstrap returns the data sample                                    
     t = bootstrap(x, datapoints)
    -
    -

    -We see that our new variance and from that the standard deviation, agrees with the central limit theorem. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We see that our new variance and from that the standard deviation, agrees with the central limit theorem.

    -











    -

    Plotting the Histogram

    -

    -

    # the histogram of the bootstrapped data (normalized data if density = True)
    +
    +
    +
    +
    +
    +
    # the histogram of the bootstrapped data (normalized data if density = True)
     n, binsboot, patches = plt.hist(t, 50, density=True, facecolor='red', alpha=0.75)
     # add a 'best fit' line  
     y = norm.pdf(binsboot, np.mean(t), np.std(t))
    @@ -1295,89 +1332,101 @@ plt.xlabel('
     plt.ylabel('Probability')
     plt.grid(True)
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    The bias-variance tradeoff

    -

    -We will discuss the bias-variance tradeoff in the context of +

    We will discuss the bias-variance tradeoff in the context of continuous predictions such as regression. However, many of the intuitions and ideas discussed here also carry over to classification tasks. Consider a dataset \( \mathcal{D} \) consisting of the data -\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +\( \mathbf{X}_\mathcal{D}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). +

    -

    -Let us assume that the true data is generated from a noisy model +

    Let us assume that the true data is generated from a noisy model

    $$ \boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} $$ -

    -where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \). +

    where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \).

    -

    -In our derivation of the ordinary least squares method we defined then +

    In our derivation of the ordinary least squares method we defined then an approximation to the function \( f \) in terms of the parameters \( \boldsymbol{\beta} \) and the design matrix \( \boldsymbol{X} \) which embody our model, -that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \). +

    -

    -Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function +

    Thereafter we found the parameters \( \boldsymbol{\beta} \) by optimizing the means squared error via the so-called cost function

    $$ C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]. $$ -

    -We can rewrite this as +

    We can rewrite this as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2. $$ -

    -The three terms represent the square of the bias of the learning +

    The three terms represent the square of the bias of the learning method, which can be thought of as the error caused by the simplifying assumptions built into the method. The second term represents the variance of the chosen model and finally the last terms is variance of the error \( \boldsymbol{\epsilon} \). +

    -

    -To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). +

    To derive this equation, we need to recall that the variance of \( \boldsymbol{y} \) and \( \boldsymbol{\epsilon} \) are both equal to \( \sigma^2 \). The mean value of \( \boldsymbol{\epsilon} \) is by definition equal to zero. Furthermore, the function \( f \) is not a stochastics variable, idem for \( \boldsymbol{\tilde{y}} \). We use a more compact notation in terms of the expectation value +

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}})^2\right], $$ -and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get +

    and adding and subtracting \( \mathbb{E}\left[\boldsymbol{\tilde{y}}\right] \) we get

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}}+\mathbb{E}\left[\boldsymbol{\tilde{y}}\right]-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right], $$ -which, using the abovementioned expectation values can be rewritten as +

    which, using the abovementioned expectation values can be rewritten as

    $$ \mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{y}-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\boldsymbol{\tilde{y}}\right]+\sigma^2, $$ -that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \). +

    that is the rewriting in terms of the so-called bias, the variance of the model \( \boldsymbol{\tilde{y}} \) and the variance of \( \boldsymbol{\epsilon} \).

    -











    -

    A way to Read the Bias-Variance Tradeoff

    -

    -



    +

    +
    +

    +
    +

    -











    -

    Example code for Bias-Variance tradeoff

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -1431,15 +1480,32 @@ plt.scatter(x_test, y_test, label.scatter(x_test, np.mean(y_pred, axis=1), label='Pred')
     plt.legend()
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Understanding what happens

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     from sklearn.linear_model import LinearRegression, Ridge, Lasso
     from sklearn.preprocessing import PolynomialFeatures
    @@ -1485,32 +1551,44 @@ plt.plot(polydegree, bias, label.plot(polydegree, variance, label='Variance')
     plt.legend()
     plt.show()
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Summing up

    -

    -The bias-variance tradeoff summarizes the fundamental tension in +

    The bias-variance tradeoff summarizes the fundamental tension in machine learning, particularly supervised learning, between the complexity of a model and the amount of training data needed to train it. Since data is often limited, in practice it is often useful to use a less-complex model with higher bias, that is a model whose asymptotic performance is worse than another model because it is easier to train and less sensitive to sampling noise arising from having a -finite-sized training dataset (smaller variance). +finite-sized training dataset (smaller variance). +

    -

    -The above equations tell us that in +

    The above equations tell us that in order to minimize the expected test error, we need to select a statistical learning method that simultaneously achieves low variance and low bias. Note that variance is inherently a nonnegative quantity, and squared bias is also nonnegative. Hence, we see that the expected test MSE can never lie below \( Var(\epsilon) \), the irreducible error. +

    -

    -What do we mean by the variance and bias of a statistical learning +

    What do we mean by the variance and bias of a statistical learning method? The variance refers to the amount by which our model would change if we estimated it using a different training data set. Since the training data are used to fit the statistical learning method, different @@ -1519,18 +1597,20 @@ estimate for our model should not vary too much between training sets. However, if a method has high variance then small changes in the training data can result in large changes in the model. In general, more flexible statistical methods have higher variance. +

    -

    -You may also find this recent article of interest. +

    You may also find this recent article of interest.

    -











    -

    Another Example from Scikit-Learn's Repository

    -

    -

    """
    +
    +
    +
    +
    +
    +
    """
     ============================
     Underfitting vs. Overfitting
     ============================
    @@ -1601,14 +1681,26 @@ plt.figure(figsize.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
             degrees[i], -scores.mean(), scores.std()))
     plt.show()
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Various steps in cross-validation

    -

    -When the repetitive splitting of the data set is done randomly, +

    When the repetitive splitting of the data set is done randomly, samples may accidently end up in a fast majority of the splits in either training or test set. Such samples may have an unbalanced influence on either model building or prediction evaluation. To avoid @@ -1621,11 +1713,10 @@ warrants a balanced representation of each sample in both training and test set over the splits. Still the division into the \( k \) subsets involves a degree of randomness. This may be fully excluded when choosing \( k=n \). This particular case is referred to as leave-one-out -cross-validation (LOOCV). +cross-validation (LOOCV). +

    -

    -

    How to set up the cross-validation for Ridge and/or Lasso

    - $$ \begin{align*} \boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T} @@ -1648,46 +1738,42 @@ $$
  • Repeat the first three steps such that each sample plays the role of the test set once.
  • Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
  • - $$ \begin{align*} \frac{1}{n} \sum_{i = 1}^n \log\{L[y_i, \mathbf{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\}. \end{align*} $$ -

    -









    +









    Cross-validation in brief

    -

    -For the various values of \( k \) +

    For the various values of \( k \)

    1. shuffle the dataset randomly.
    2. Split the dataset into \( k \) groups.
    3. For each unique group: -
      1. Decide which group to use as set for test data
      2. Take the remaining groups as a training data set
      3. Fit a model on the training set and evaluate it on the test set
      4. Retain the evaluation score and discard the model
      -
    4. Summarize the model using the sample of model evaluation scores
    -









    -

    Code Example for Cross-validation and \( k \)-fold Cross-validation

    -

    -The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial. -

    +

    The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial.

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.model_selection import KFold
     from sklearn.linear_model import Ridge
    @@ -1776,16 +1862,33 @@ plt.ylabel('
     plt.legend()
     
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    More examples on bootstrap and cross-validation and errors

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -1863,21 +1966,35 @@ plt.xlabel('
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    -Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.

    -

    -

    The same example but now with cross-validation

    -

    -In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error. -

    +

    In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -1944,18 +2061,25 @@ plt.xlabel('
     plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + - -
    - © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz index d63efe22f..21fbd22a2 100644 Binary files a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz and b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz differ diff --git a/doc/pub/week37/ipynb/week37.ipynb b/doc/pub/week37/ipynb/week37.ipynb index 248b41046..b74514edc 100644 --- a/doc/pub/week37/ipynb/week37.ipynb +++ b/doc/pub/week37/ipynb/week37.ipynb @@ -2,44 +2,69 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "id": "a5836dde", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "de302286", + "metadata": { + "editable": true + }, "source": [ - "\n", "# Week 37: Summary of Ridge and Lasso Regression and Resampling Methods\n", - "\n", - " \n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **Sep 28, 2021**\n", - "\n", - "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", - "\n", - "\n", + "Date: **Aug 23, 2022**\n", "\n", + "Copyright 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" + ] + }, + { + "cell_type": "markdown", + "id": "d650d109", + "metadata": { + "editable": true + }, + "source": [ "## Plans for week 37\n", "\n", - "* Thursday September 16: Summary of Ridge and Lasso with examples and start resampling techniques\n", - "\n", - "a. [Video of Lecture, first part](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember16Firstpart.mp4?vrtx=view-as-webpage)\n", - "\n", - "b. [Video of Lecture, second part](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember16SecondPart.mp4?vrtx=view-as-webpage)\n", - "\n", - "\n", - "* Friday September 17: Resampling methods, Cross-validation, Bootstrapping and jackknife\n", - "\n", - "a. [Video of Lecture](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember17.mp4?vrtx=view-as-webpage)\n", + "* Thursday September 15: Summary of Ridge and Lasso with examples and start resampling techniques\n", "\n", + "* Friday September 16: Resampling methods, Cross-validation, Bootstrapping and jackknife\n", "\n", "Recommended Reading:\n", "1. Lectures on Resampling methods (these lectures)\n", "\n", "2. Bishop 1.3 (cross-validation) and 3.2 (bias-variance tradeoff)\n", "\n", - "3. Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap). This chapter is better than Bishop's on these topics. Goodfellow et al discuss this in a superficial way in sections 5.2-5.5.\n", - "\n", - "## Thursday September 16, Summary of Ridge and Lasso Regression and start Resampling methods\n", - "\n", - "\n", + "3. Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) and 7.11 (bootstrap). This chapter is better than Bishop's on these topics. Goodfellow et al discuss this in a superficial way in sections 5.2-5.5." + ] + }, + { + "cell_type": "markdown", + "id": "5211d648", + "metadata": { + "editable": true + }, + "source": [ + "## Thursday September 15, Summary of Ridge and Lasso Regression and start Resampling methods" + ] + }, + { + "cell_type": "markdown", + "id": "b0230391", + "metadata": { + "editable": true + }, + "source": [ "## Deriving OLS from a probability distribution\n", "\n", "Our basic assumption when we derived the OLS equations was to assume\n", @@ -58,7 +83,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d6189db5", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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]}.\n", @@ -67,7 +95,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "55a53842", + "metadata": { + "editable": true + }, "source": [ "## Independent and Identically Distrubuted (iid)\n", "\n", @@ -77,7 +108,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "97824eab", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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]},\n", @@ -86,7 +120,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "fdd01f7b", + "metadata": { + "editable": true + }, "source": [ "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}$.\n", "\n", @@ -95,7 +132,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c7f8b3d9", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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}).\n", @@ -104,7 +144,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b07a549e", + "metadata": { + "editable": true + }, "source": [ "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\n", "in case we have a simple one-dimensional input and output case" @@ -112,7 +155,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bfb43e03", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\\dots, (x_{n-1},y_{n-1})].\n", @@ -121,7 +167,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "99716b64", + "metadata": { + "editable": true + }, "source": [ "In the more general case the various inputs should be replaced by the possible features represented by the input data set $\\boldsymbol{X}$. \n", "We can now rewrite the above probability as" @@ -129,7 +178,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "9d019eab", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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]}.\n", @@ -138,10 +190,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "735e18d1", + "metadata": { + "editable": true + }, + "source": [ + "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}$." + ] + }, + { + "cell_type": "markdown", + "id": "9900f359", + "metadata": { + "editable": true + }, "source": [ - "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}$.\n", - "\n", "## Maximum Likelihood Estimation (MLE)\n", "\n", "In statistics, maximum likelihood estimation (MLE) is a method of\n", @@ -150,14 +213,12 @@ "function so that, under the assumed statistical model, the observed\n", "data is the most probable. \n", "\n", - "\n", "We will assume here that our events are given by the above Gaussian\n", "distribution and we will determine the optimal parameters $\\beta$ by\n", "maximizing the above PDF. However, computing the derivatives of a\n", "product function is cumbersome and can easily lead to overflow and/or\n", "underflowproblems, with potentials for loss of numerical precision.\n", "\n", - "\n", "In practice, it is more convenient to maximize the logarithm of the\n", "PDF because it is a monotonically increasing function of the argument.\n", "Alternatively, and this will be our option, we will minimize the\n", @@ -165,10 +226,16 @@ "function.\n", "\n", "Note also that maximization/minimization of the logarithm of the PDF\n", - "is equivalent to the maximization/minimization of the function itself.\n", - "\n", - "\n", - "\n", + "is equivalent to the maximization/minimization of the function itself." + ] + }, + { + "cell_type": "markdown", + "id": "f73eb18f", + "metadata": { + "editable": true + }, + "source": [ "## A new Cost Function\n", "\n", "We could now define a new cost function to minimize, namely the negative logarithm of the above PDF" @@ -176,7 +243,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c2b1885a", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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})},\n", @@ -185,14 +255,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4d6140ee", + "metadata": { + "editable": true + }, "source": [ "which becomes" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "062a201d", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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}.\n", @@ -201,14 +277,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "96498f2d", + "metadata": { + "editable": true + }, "source": [ "Taking the derivative of the *new* cost function with respect to the parameters $\\beta$ we recognize our familiar OLS equation, namely" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "7c187e5e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right) =0,\n", @@ -217,14 +299,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "32b99a15", + "metadata": { + "editable": true + }, "source": [ "which leads to the well-known OLS equation for the optimal paramters $\\beta$" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "61b4886b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\hat{\\boldsymbol{\\beta}}^{\\mathrm{OLS}}=\\left(\\boldsymbol{X}^T\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^T\\boldsymbol{y}!\n", @@ -233,7 +321,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "05e977f0", + "metadata": { + "editable": true + }, "source": [ "## Bayes' Theorem\n", "\n", @@ -242,7 +333,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "3c3f40e2", + "metadata": { + "editable": true + }, "source": [ "$$\n", "p(X\\vert Y)= \\frac{p(X,Y)}{p(Y)},\n", @@ -251,14 +345,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "865433b0", + "metadata": { + "editable": true + }, "source": [ "which we can rewrite as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "1325bce7", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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)},\n", @@ -267,10 +367,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "eea47267", + "metadata": { + "editable": true + }, + "source": [ + "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$." + ] + }, + { + "cell_type": "markdown", + "id": "92bd39ff", + "metadata": { + "editable": true + }, "source": [ - "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$. \n", - "\n", "## Interpretations of Bayes' Theorem\n", "\n", "The quantity $p(Y\\vert X)$ on the right-hand side of the theorem is\n", @@ -278,8 +389,16 @@ "the parameter space represented by $X$. This function is not\n", "necesseraly normalized and is normally called the likelihood function.\n", "\n", - "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.\n", - "\n", + "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." + ] + }, + { + "cell_type": "markdown", + "id": "84852c9b", + "metadata": { + "editable": true + }, + "source": [ "## Test Function for what happens with OLS, Ridge and Lasso\n", "\n", "We will play around with a study of the values for the optimal\n", @@ -293,8 +412,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 1, + "id": "9a907bbe", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "%matplotlib inline\n", @@ -366,11 +489,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "49bfb836", + "metadata": { + "editable": true + }, + "source": [ + "How can we understand this?" + ] + }, + { + "cell_type": "markdown", + "id": "88f19610", + "metadata": { + "editable": true + }, "source": [ - "How can we understand this? \n", - "\n", - "\n", "## Rerunning the above code\n", "\n", "Let us write out the values of the coefficients $\\beta_i$ as functions\n", @@ -395,8 +528,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 2, + "id": "4835de12", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np\n", @@ -441,7 +578,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "fc7b0f49", + "metadata": { + "editable": true + }, "source": [ "## Invoking Bayes' theorem\n", "\n", @@ -452,7 +592,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "42f06212", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\\dots, (x_{n-1},y_{n-1})],\n", @@ -461,14 +604,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "fa1e63d0", + "metadata": { + "editable": true + }, "source": [ "is given by" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "fa9568ba", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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]}.\n", @@ -477,14 +626,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "054a3391", + "metadata": { + "editable": true + }, "source": [ "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" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "82284422", + "metadata": { + "editable": true + }, "source": [ "$$\n", "p(\\boldsymbol{\\beta}\\vert\\boldsymbol{D}).\n", @@ -493,14 +648,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "47b66ae4", + "metadata": { + "editable": true + }, "source": [ "Bayes' theorem comes to our rescue here since (omitting the normalization constant)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "1a5003d7", + "metadata": { + "editable": true + }, "source": [ "$$\n", "p(\\boldsymbol{\\beta}\\vert\\boldsymbol{D})\\propto p(\\boldsymbol{D}\\vert\\boldsymbol{\\beta})p(\\boldsymbol{\\beta}).\n", @@ -509,11 +670,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "78330f1c", + "metadata": { + "editable": true + }, + "source": [ + "We have a model for $p(\\boldsymbol{D}\\vert\\boldsymbol{\\beta})$ but need one for the **prior** $p(\\boldsymbol{\\beta}$!" + ] + }, + { + "cell_type": "markdown", + "id": "64d20bda", + "metadata": { + "editable": true + }, "source": [ - "We have a model for $p(\\boldsymbol{D}\\vert\\boldsymbol{\\beta})$ but need one for the **prior** $p(\\boldsymbol{\\beta}$! \n", - "\n", - "\n", "## Ridge and Bayes\n", "\n", "With the posterior probability defined by a likelihood which we have\n", @@ -525,7 +696,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "efb6bc3e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "p(\\boldsymbol{\\beta})=\\prod_{j=0}^{p-1}\\exp{\\left(-\\frac{\\beta_j^2}{2\\tau^2}\\right)}.\n", @@ -534,14 +708,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "631f9bbf", + "metadata": { + "editable": true + }, "source": [ "Our posterior probability becomes then (omitting the normalization factor which is just a constant)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "be11a176", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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)}.\n", @@ -550,7 +730,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "5d93b043", + "metadata": { + "editable": true + }, "source": [ "We can now optimize this quantity with respect to $\\boldsymbol{\\beta}$. As we\n", "did for OLS, this is most conveniently done by taking the negative\n", @@ -560,7 +743,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "2342a3d1", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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,\n", @@ -569,14 +755,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "afefb69b", + "metadata": { + "editable": true + }, "source": [ "and replacing $1/2\\tau^2$ with $\\lambda$ we have" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "ff127df8", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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,\n", @@ -585,10 +777,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "6f0ee10a", + "metadata": { + "editable": true + }, + "source": [ + "which is our Ridge cost function! Nice, isn't it?" + ] + }, + { + "cell_type": "markdown", + "id": "bc40b459", + "metadata": { + "editable": true + }, "source": [ - "which is our Ridge cost function! Nice, isn't it?\n", - "\n", "## Lasso and Bayes\n", "\n", "To derive the Lasso cost function, we simply replace the Gaussian prior with an exponential distribution ([Laplace in this case](https://en.wikipedia.org/wiki/Laplace_distribution)) with zero mean value, that is" @@ -596,7 +799,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f0836068", + "metadata": { + "editable": true + }, "source": [ "$$\n", "p(\\boldsymbol{\\beta})=\\prod_{j=0}^{p-1}\\exp{\\left(-\\frac{\\vert\\beta_j\\vert}{\\tau}\\right)}.\n", @@ -605,14 +811,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "400856ed", + "metadata": { + "editable": true + }, "source": [ "Our posterior probability becomes then (omitting the normalization factor which is just a constant)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "63922ca3", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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)}.\n", @@ -621,7 +833,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0fbcdb4a", + "metadata": { + "editable": true + }, "source": [ "Taking the negative\n", "logarithm of the posterior probability and leaving out the\n", @@ -630,7 +845,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "712779ec", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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,\n", @@ -639,14 +857,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "5148d55d", + "metadata": { + "editable": true + }, "source": [ "and replacing $1/\\tau$ with $\\lambda$ we have" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "c70250d8", + "metadata": { + "editable": true + }, "source": [ "$$\n", "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,\n", @@ -655,12 +879,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "41677ce1", + "metadata": { + "editable": true + }, + "source": [ + "which is our Lasso cost function!" + ] + }, + { + "cell_type": "markdown", + "id": "9fed0f7b", + "metadata": { + "editable": true + }, "source": [ - "which is our Lasso cost function! \n", - "\n", - "\n", - "\n", "## Why resampling methods\n", "\n", "Before we proceed, we need to rethink what we have been doing. In our\n", @@ -670,12 +903,16 @@ "\n", "2. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more\n", "\n", - "and discuss how to select a given model (one of the difficult parts in machine learning).\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "and discuss how to select a given model (one of the difficult parts in machine learning)." + ] + }, + { + "cell_type": "markdown", + "id": "0bcc8118", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods\n", "Resampling methods are an indispensable tool in modern\n", "statistics. They involve repeatedly drawing samples from a training\n", @@ -694,11 +931,16 @@ "2. and **Cross-Validation**\n", "\n", "In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular\n", - "cross-validation and the bootstrap method.\n", - "\n", - "\n", - "\n", - "\n", + "cross-validation and the bootstrap method." + ] + }, + { + "cell_type": "markdown", + "id": "8cc62c36", + "metadata": { + "editable": true + }, + "source": [ "## Resampling approaches can be computationally expensive\n", "\n", "Resampling approaches can be computationally expensive, because they\n", @@ -715,22 +957,33 @@ "of flexibility. The process of evaluating a model’s performance is\n", "known as model assessment, whereas the process of selecting the proper\n", "level of flexibility for a model is known as model selection. The\n", - "bootstrap is widely used.\n", - "\n", - "\n", - "\n", + "bootstrap is widely used." + ] + }, + { + "cell_type": "markdown", + "id": "b24f01bb", + "metadata": { + "editable": true + }, + "source": [ "## Why resampling methods ?\n", "**Statistical analysis.**\n", "\n", - "\n", "* Our simulations can be treated as *computer experiments*. This is particularly the case for Monte Carlo methods which are widely used in statistical analyses.\n", "\n", "* The results can be analysed with the same statistical tools as we would use when analysing experimental data.\n", "\n", - "* As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.\n", - "\n", - " \n", - "\n", + "* As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors." + ] + }, + { + "cell_type": "markdown", + "id": "60020fbe", + "metadata": { + "editable": true + }, + "source": [ "## Statistical analysis\n", "\n", "* As in other experiments, many numerical experiments have two classes of errors:\n", @@ -739,17 +992,18 @@ "\n", " * Systematical errors\n", "\n", - "\n", "* Statistical errors can be estimated using standard tools from statistics\n", "\n", - "* Systematical errors are method specific and must be treated differently from case to case.\n", - "\n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", + "* Systematical errors are method specific and must be treated differently from case to case." + ] + }, + { + "cell_type": "markdown", + "id": "41cf8945", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods\n", "\n", "With all these analytical equations for both the OLS and Ridge\n", @@ -769,11 +1023,16 @@ "\n", "As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error.\n", "For a certain level of complexity the test error will reach minimum, before starting to increase again. The\n", - "training error reaches a saturation.\n", - "\n", - "\n", - "\n", - "\n", + "training error reaches a saturation." + ] + }, + { + "cell_type": "markdown", + "id": "66aecc7c", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: Jackknife and Bootstrap\n", "\n", "Two famous\n", @@ -789,8 +1048,16 @@ "satisfied, the methods will fail. Yet, it should be said that if the data are\n", "independent, identically distributed, and we only want to estimate the\n", "variance of $\\overline{X}$ (which often is the case), then there is no\n", - "need for bootstrapping. \n", - "\n", + "need for bootstrapping." + ] + }, + { + "cell_type": "markdown", + "id": "78700d5d", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: Jackknife\n", "\n", "The Jackknife works by making many replicas of the estimator $\\widehat{\\beta}$. \n", @@ -800,7 +1067,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d3102055", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{x}_i = (x_1,x_2,\\cdots,x_{i-1},x_{i+1},\\cdots,x_n),\n", @@ -809,21 +1079,35 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "38ea20e9", + "metadata": { + "editable": true + }, "source": [ "which equals the vector $\\boldsymbol{x}$ with the exception that observation\n", "number $i$ is left out. Using this notation, define\n", "$\\widehat{\\beta}_i$ to be the estimator\n", - "$\\widehat{\\beta}$ computed using $\\vec{X}_i$. \n", - "\n", - "\n", + "$\\widehat{\\beta}$ computed using $\\vec{X}_i$." + ] + }, + { + "cell_type": "markdown", + "id": "210f00d2", + "metadata": { + "editable": true + }, + "source": [ "## Jackknife code example" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 3, + "id": "e84a76b6", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "from numpy import *\n", @@ -858,7 +1142,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "9aea7387", + "metadata": { + "editable": true + }, "source": [ "## Resampling methods: Bootstrap\n", "Bootstrapping is a non-parametric approach to statistical inference\n", @@ -873,16 +1160,20 @@ "\n", "4. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).\n", "\n", - "\n", - "\n", "The textbook by [Davison on the Bootstrap Methods and their Applications](https://www.cambridge.org/core/books/bootstrap-methods-and-their-application/ED2FD043579F27952363566DC09CBD6A) provides many more insights and proofs. In this course we will take a more practical approach and use the results and theorems provided in the literature. For those interested in reading more about the bootstrap methods, we recommend the above text and the one by [Efron and Tibshirani](https://www.routledge.com/An-Introduction-to-the-Bootstrap/Efron-Tibshirani/p/book/9780412042317).\n", "\n", - "\n", - "Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called **central limit theorem**.\n", - "\n", + "Before we proceed however, we need to remind ourselves about a central theorem in statistics, namely the so-called **central limit theorem**." + ] + }, + { + "cell_type": "markdown", + "id": "6ea854bb", + "metadata": { + "editable": true + }, + "source": [ "## The Central Limit Theorem\n", "\n", - "\n", "Suppose we have a PDF $p(x)$ from which we generate a series $N$\n", "of averages $\\mathbb{E}[x_i]$. Each mean value $\\mathbb{E}[x_i]$\n", "is viewed as the average of a specific measurement, e.g., throwing \n", @@ -896,7 +1187,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e192b627", + "metadata": { + "editable": true + }, "source": [ "$$\n", "z=\\frac{x_1+x_2+\\dots+x_m}{m},\n", @@ -905,10 +1199,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "8f128f3b", + "metadata": { + "editable": true + }, + "source": [ + "the question we pose is which is the PDF of the new variable $z$." + ] + }, + { + "cell_type": "markdown", + "id": "19c8552a", + "metadata": { + "editable": true + }, "source": [ - "the question we pose is which is the PDF of the new variable $z$.\n", - "\n", "## Finding the Limit\n", "\n", "The probability of obtaining an average value $z$ is the product of the \n", @@ -919,7 +1224,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a8b8dd44", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\tilde{p}(z)=\\int dx_1p(x_1)\\int dx_2p(x_2)\\dots\\int dx_mp(x_m)\n", @@ -929,14 +1237,24 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "efad3667", + "metadata": { + "editable": true + }, "source": [ "where the $\\delta$-function enbodies the constraint that the mean is $z$.\n", "All measurements that lead to each individual $x_i$ are expected to\n", "be independent, which in turn means that we can express $\\tilde{p}$ as the \n", - "product of individual $p(x_i)$. The independence assumption is important in the derivation of the central limit theorem.\n", - "\n", - "\n", + "product of individual $p(x_i)$. The independence assumption is important in the derivation of the central limit theorem." + ] + }, + { + "cell_type": "markdown", + "id": "e8bc1f23", + "metadata": { + "editable": true + }, + "source": [ "## Rewriting the $\\delta$-function\n", "\n", "If we use the integral expression for the $\\delta$-function" @@ -944,7 +1262,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "09f6d895", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\delta(z-\\frac{x_1+x_2+\\dots+x_m}{m})=\\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\n", @@ -954,7 +1275,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "633c3dad", + "metadata": { + "editable": true + }, "source": [ "and inserting $e^{i\\mu q-i\\mu q}$ where $\\mu$ is the mean value\n", "we arrive at" @@ -962,7 +1286,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "5b6bbf58", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\tilde{p}(z)=\\frac{1}{2\\pi}\\int_{-\\infty}^{\\infty}\n", @@ -973,14 +1300,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a2616b84", + "metadata": { + "editable": true + }, "source": [ "with the integral over $x$ resulting in" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "14ad8d5e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\int_{-\\infty}^{\\infty}dxp(x)\\exp{\\left(iq(\\mu-x)/m\\right)}=\n", @@ -991,7 +1324,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4fb90d4e", + "metadata": { + "editable": true + }, "source": [ "## Identifying Terms\n", "\n", @@ -1001,7 +1337,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ebe09cb1", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\int_{-\\infty}^{\\infty}dxp(x)e^{\\left(iq(\\mu-x)/m\\right)}=\n", @@ -1011,14 +1350,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e077c46b", + "metadata": { + "editable": true + }, "source": [ "resulting in" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "23dbf693", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\left[\\int_{-\\infty}^{\\infty}dxp(x)\\exp{\\left(iq(\\mu-x)/m\\right)}\\right]^m\\approx\n", @@ -1028,14 +1373,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c2ff645f", + "metadata": { + "editable": true + }, "source": [ "and in the limit $m\\rightarrow \\infty$ we obtain" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "521a88bf", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\tilde{p}(z)=\\frac{1}{\\sqrt{2\\pi}(\\sigma/\\sqrt{m})}\n", @@ -1045,12 +1396,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "8654dfdb", + "metadata": { + "editable": true + }, "source": [ "which is the normal distribution with variance\n", "$\\sigma^2_m=\\sigma^2/m$, where $\\sigma$ is the variance of the PDF $p(x)$\n", - "and $\\mu$ is also the mean of the PDF $p(x)$. \n", - "\n", + "and $\\mu$ is also the mean of the PDF $p(x)$." + ] + }, + { + "cell_type": "markdown", + "id": "ea9bfca5", + "metadata": { + "editable": true + }, + "source": [ "## Wrapping it up\n", "\n", "Thus, the central limit theorem states that the PDF $\\tilde{p}(z)$ of\n", @@ -1065,7 +1427,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "68a40c8a", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\sigma_m=\n", @@ -1075,7 +1440,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "18961d1c", + "metadata": { + "editable": true + }, "source": [ "The latter is true only if the average value is known exactly. This is obtained in the limit\n", "$m\\rightarrow \\infty$ only. Because the mean and the variance are measured quantities we obtain \n", @@ -1084,7 +1452,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "27733cdc", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\sigma_m\\approx \n", @@ -1094,7 +1465,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "67873daf", + "metadata": { + "editable": true + }, "source": [ "In many cases however the above estimate for the standard deviation,\n", "in particular if correlations are strong, may be too simplistic. Keep\n", @@ -1104,13 +1478,18 @@ "we generate in various calculations do always exhibit some\n", "correlations.\n", "\n", - "\n", - "\n", "The theorem is satisfied by a large class of PDFs. Note however that for a\n", "finite $m$, it is not always possible to find a closed form /analytic expression for\n", - "$\\tilde{p}(x)$.\n", - "\n", - "\n", + "$\\tilde{p}(x)$." + ] + }, + { + "cell_type": "markdown", + "id": "c3070b0e", + "metadata": { + "editable": true + }, + "source": [ "## Confidence Intervals\n", "\n", "Confidence intervals are used in statistics and represent a type of estimate\n", @@ -1124,9 +1503,16 @@ "$\\boldsymbol{\\sigma}^2 (\\boldsymbol{\\beta}_j ) = \\boldsymbol{\\sigma}^2 [(\\mathbf{X}^{T} \\mathbf{X})^{-1}]_{jj} $.\n", "\n", "This quantity will be used to\n", - "construct a confidence interval for the estimates.\n", - "\n", - "\n", + "construct a confidence interval for the estimates." + ] + }, + { + "cell_type": "markdown", + "id": "6882d3ef", + "metadata": { + "editable": true + }, + "source": [ "## Standard Approach based on the Normal Distribution\n", "\n", "We will assume that the parameters $\\beta$ follow a normal\n", @@ -1137,7 +1523,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "93b856bb", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\left(\\mu_{\\beta}\\pm \\frac{z\\sigma_{\\beta}}{\\sqrt{n}}\\right),\n", @@ -1146,7 +1535,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "018c758d", + "metadata": { + "editable": true + }, "source": [ "where $z$ defines the level of certainty (or confidence). For a normal\n", "distribution typical parameters are $z=2.576$ which corresponds to a\n", @@ -1158,8 +1550,16 @@ "For more discussions of confidence intervals (and in particular linked with a discussion of the bootstrap method), see chapter 5 of the textbook by [Davison on the Bootstrap Methods and their Applications](https://www.cambridge.org/core/books/bootstrap-methods-and-their-application/ED2FD043579F27952363566DC09CBD6A)\n", "\n", "In this text you will also find an in-depth discussion of the\n", - "Bootstrap method, why it works and various theorems related to it. \n", - "\n", + "Bootstrap method, why it works and various theorems related to it." + ] + }, + { + "cell_type": "markdown", + "id": "8b809f29", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: Bootstrap background\n", "\n", "Since $\\widehat{\\beta} = \\widehat{\\beta}(\\boldsymbol{X})$ is a function of random variables,\n", @@ -1170,9 +1570,16 @@ "in the place of $p(\\boldsymbol{t})$. If the relative frequency closely\n", "resembles $p(\\vec{t})$, then using numerics, it is straight forward to\n", "estimate all the interesting parameters of $p(\\boldsymbol{t})$ using point\n", - "estimators. \n", - "\n", - "\n", + "estimators." + ] + }, + { + "cell_type": "markdown", + "id": "b4ac826b", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: More Bootstrap background\n", "\n", "In the case that $\\widehat{\\beta}$ has\n", @@ -1187,8 +1594,16 @@ "By repeated use of the above two points, many\n", "estimates of $\\widehat{\\beta}$ can be obtained. The\n", "idea is to use the relative frequency of $\\widehat{\\beta}^*$\n", - "(think of a histogram) as an estimate of $p(\\boldsymbol{t})$.\n", - "\n", + "(think of a histogram) as an estimate of $p(\\boldsymbol{t})$." + ] + }, + { + "cell_type": "markdown", + "id": "0667797d", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: Bootstrap approach\n", "\n", "But\n", @@ -1200,10 +1615,16 @@ "\n", "If we draw observations in accordance with\n", "the relative frequency of the observations, will we obtain the same\n", - "result in some asymptotic sense? The answer is yes.\n", - "\n", - "\n", - "\n", + "result in some asymptotic sense? The answer is yes." + ] + }, + { + "cell_type": "markdown", + "id": "59db77ae", + "metadata": { + "editable": true + }, + "source": [ "## Resampling methods: Bootstrap steps\n", "\n", "The independent bootstrap works like this: \n", @@ -1224,9 +1645,16 @@ "you use the estimators corresponding to the statistic of interest. For\n", "example, if you are interested in estimating the variance of $\\widehat\n", "\\beta$, apply the etsimator $\\widehat \\sigma^2$ to the values\n", - "$\\widehat \\beta^*$.\n", - "\n", - "\n", + "$\\widehat \\beta^*$." + ] + }, + { + "cell_type": "markdown", + "id": "94476991", + "metadata": { + "editable": true + }, + "source": [ "## Code example for the Bootstrap method\n", "\n", "The following code starts with a Gaussian distribution with mean value\n", @@ -1245,8 +1673,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 4, + "id": "c021fa6c", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np\n", @@ -1279,17 +1711,32 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bfb64264", + "metadata": { + "editable": true + }, + "source": [ + "We see that our new variance and from that the standard deviation, agrees with the central limit theorem." + ] + }, + { + "cell_type": "markdown", + "id": "4f4554da", + "metadata": { + "editable": true + }, "source": [ - "We see that our new variance and from that the standard deviation, agrees with the central limit theorem.\n", - "\n", "## Plotting the Histogram" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 5, + "id": "1b8d9567", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# the histogram of the bootstrapped data (normalized data if density = True)\n", @@ -1305,11 +1752,13 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "15b3abb8", + "metadata": { + "editable": true + }, "source": [ "## The bias-variance tradeoff\n", "\n", - "\n", "We will discuss the bias-variance tradeoff in the context of\n", "continuous predictions such as regression. However, many of the\n", "intuitions and ideas discussed here also carry over to classification\n", @@ -1321,7 +1770,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "75b22667", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{y}=f(\\boldsymbol{x}) + \\boldsymbol{\\epsilon}\n", @@ -1330,7 +1782,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "75bc3237", + "metadata": { + "editable": true + }, "source": [ "where $\\epsilon$ is normally distributed with mean zero and standard deviation $\\sigma^2$.\n", "\n", @@ -1344,7 +1799,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c2cadf6b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "C(\\boldsymbol{X},\\boldsymbol{\\beta}) =\\frac{1}{n}\\sum_{i=0}^{n-1}(y_i-\\tilde{y}_i)^2=\\mathbb{E}\\left[(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}})^2\\right].\n", @@ -1353,14 +1811,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "198df5d7", + "metadata": { + "editable": true + }, "source": [ "We can rewrite this as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "3a5dee4e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbb{E}\\left[(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}})^2\\right]=\\frac{1}{n}\\sum_i(f_i-\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right])^2+\\frac{1}{n}\\sum_i(\\tilde{y}_i-\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right])^2+\\sigma^2.\n", @@ -1369,7 +1833,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c961e418", + "metadata": { + "editable": true + }, "source": [ "The three terms represent the square of the bias of the learning\n", "method, which can be thought of as the error caused by the simplifying\n", @@ -1383,7 +1850,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f2157a6d", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbb{E}\\left[(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}})^2\\right]=\\mathbb{E}\\left[(\\boldsymbol{f}+\\boldsymbol{\\epsilon}-\\boldsymbol{\\tilde{y}})^2\\right],\n", @@ -1392,14 +1862,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e3ec5e46", + "metadata": { + "editable": true + }, "source": [ "and adding and subtracting $\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right]$ we get" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e5a63c4e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbb{E}\\left[(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}})^2\\right]=\\mathbb{E}\\left[(\\boldsymbol{f}+\\boldsymbol{\\epsilon}-\\boldsymbol{\\tilde{y}}+\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right]-\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right])^2\\right],\n", @@ -1408,14 +1884,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "91c199d1", + "metadata": { + "editable": true + }, "source": [ "which, using the abovementioned expectation values can be rewritten as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "a1ad8200", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbb{E}\\left[(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}})^2\\right]=\\mathbb{E}\\left[(\\boldsymbol{y}-\\mathbb{E}\\left[\\boldsymbol{\\tilde{y}}\\right])^2\\right]+\\mathrm{Var}\\left[\\boldsymbol{\\tilde{y}}\\right]+\\sigma^2,\n", @@ -1424,26 +1906,48 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "61443eec", + "metadata": { + "editable": true + }, + "source": [ + "that is the rewriting in terms of the so-called bias, the variance of the model $\\boldsymbol{\\tilde{y}}$ and the variance of $\\boldsymbol{\\epsilon}$." + ] + }, + { + "cell_type": "markdown", + "id": "ba72804c", + "metadata": { + "editable": true + }, "source": [ - "that is the rewriting in terms of the so-called bias, the variance of the model $\\boldsymbol{\\tilde{y}}$ and the variance of $\\boldsymbol{\\epsilon}$.\n", - "\n", - "\n", "## A way to Read the Bias-Variance Tradeoff\n", "\n", "\n", "\n", - "

    Figure 1:

    \n", - "\n", - "\n", "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "036ec362", + "metadata": { + "editable": true + }, + "source": [ "## Example code for Bias-Variance tradeoff" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 6, + "id": "f811f079", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -1504,15 +2008,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "22336b54", + "metadata": { + "editable": true + }, "source": [ "## Understanding what happens" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 7, + "id": "f317126f", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -1565,14 +2076,13 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c5da7b85", + "metadata": { + "editable": true + }, "source": [ - "\n", "## Summing up\n", "\n", - "\n", - "\n", - "\n", "The bias-variance tradeoff summarizes the fundamental tension in\n", "machine learning, particularly supervised learning, between the\n", "complexity of a model and the amount of training data needed to train\n", @@ -1582,8 +2092,6 @@ "train and less sensitive to sampling noise arising from having a\n", "finite-sized training dataset (smaller variance). \n", "\n", - "\n", - "\n", "The above equations tell us that in\n", "order to minimize the expected test error, we need to select a\n", "statistical learning method that simultaneously achieves low variance\n", @@ -1591,7 +2099,6 @@ "and squared bias is also nonnegative. Hence, we see that the expected\n", "test MSE can never lie below $Var(\\epsilon)$, the irreducible error.\n", "\n", - "\n", "What do we mean by the variance and bias of a statistical learning\n", "method? The variance refers to the amount by which our model would change if we\n", "estimated it using a different training data set. Since the training\n", @@ -1602,16 +2109,27 @@ "the training data can result in large changes in the model. In general, more\n", "flexible statistical methods have higher variance.\n", "\n", - "\n", - "You may also find this recent [article](https://www.pnas.org/content/116/32/15849) of interest.\n", - "\n", + "You may also find this recent [article](https://www.pnas.org/content/116/32/15849) of interest." + ] + }, + { + "cell_type": "markdown", + "id": "6ad35a51", + "metadata": { + "editable": true + }, + "source": [ "## Another Example from Scikit-Learn's Repository" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 8, + "id": "f08dfc81", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "\"\"\"\n", @@ -1689,9 +2207,11 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "2a30946d", + "metadata": { + "editable": true + }, "source": [ - "\n", "## Various steps in cross-validation\n", "\n", "When the repetitive splitting of the data set is done randomly,\n", @@ -1707,9 +2227,16 @@ "test set over the splits. Still the division into the $k$ subsets\n", "involves a degree of randomness. This may be fully excluded when\n", "choosing $k=n$. This particular case is referred to as leave-one-out\n", - "cross-validation (LOOCV). \n", - "\n", - "\n", + "cross-validation (LOOCV)." + ] + }, + { + "cell_type": "markdown", + "id": "f5f6a90c", + "metadata": { + "editable": true + }, + "source": [ "## How to set up the cross-validation for Ridge and/or Lasso\n", "\n", "* Define a range of interest for the penalty parameter.\n", @@ -1721,7 +2248,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "064b458c", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\begin{align*}\n", @@ -1734,7 +2264,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c92ee0ac", + "metadata": { + "editable": true + }, "source": [ "* Evaluate the prediction performance of these models on the test set by $[y_i, \\boldsymbol{X}_{i, \\ast}; \\boldsymbol{\\beta}_{-i}(\\lambda), \\boldsymbol{\\sigma}_{-i}^2(\\lambda)]$. Or, by the prediction error $|y_i - \\boldsymbol{X}_{i, \\ast} \\boldsymbol{\\beta}_{-i}(\\lambda)|$, the relative error, the error squared or the R2 score function.\n", "\n", @@ -1745,7 +2278,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c716756d", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\begin{align*}\n", @@ -1756,7 +2292,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "7ea72d6a", + "metadata": { + "editable": true + }, "source": [ "## Cross-validation in brief\n", "\n", @@ -1776,9 +2315,16 @@ "\n", "d. Retain the evaluation score and discard the model\n", "\n", - "\n", - "5. Summarize the model using the sample of model evaluation scores\n", - "\n", + "5. Summarize the model using the sample of model evaluation scores" + ] + }, + { + "cell_type": "markdown", + "id": "73614785", + "metadata": { + "editable": true + }, + "source": [ "## Code Example for Cross-validation and $k$-fold Cross-validation\n", "\n", "The code here uses Ridge regression with cross-validation (CV) resampling and $k$-fold CV in order to fit a specific polynomial." @@ -1786,22 +2332,13 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEGCAYAAABvtY4XAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAA3c0lEQVR4nO3dd3gU5fr/8fedRhIICYRQQwmdAKEX6UUpggLiEURQ0CMqKvaf7dg5ikeP9SiKigVRiiIioIBUkRpa6D20UBJKII2UfX5/ZOGLECCJmZ3dzf26rlwkO7NzfzYhd2afmXlGjDEopZTyPj52B1BKKWUNbfBKKeWltMErpZSX0gavlFJeShu8Ukp5KT+7A1ysXLlypkaNGnbHUEopj7F27dokY0xEXsvcqsHXqFGD2NhYu2MopZTHEJH9V1qmQzRKKeWltMErpZSX0gavlFJeyq3G4POSlZXFoUOHyMjIsDuKKoTAwEAiIyPx9/e3O4pSxY7bN/hDhw4REhJCjRo1EBG746gCMMZw4sQJDh06RFRUlN1xlCp23H6IJiMjg/DwcG3uHkhECA8P13dfStnE7Rs8oM3dg+nPTin7uP0QjVLKvRzdtJP9X36POXOGErf0p2nvDvqH3E1pg1dK5YtxOFg18imaffUhFXOyABieHELGIT/+e1tTqoQF2ZxQXcojhmjUtcXHx9OoUSO7YygvZRwOVvW/i7ZfvMOWFp04vCaOtJOnuf6RoWw5fIaJd/+LhHVb7I6pLqF78H9TdnY2fn7F79tYXF93cTVp5X7iUwJwDBjBdT98jvjk7hsO7RBKizBfKr59G6dX/ET6to0EhYXYnF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x+b6Ad84ZzxcCYSJSCXnsoHAZReYiEhrEVnhnEd8uYjUcz4+XERmOGvHO981PO5cb6WIlL1oM8OcFyJtFpHWzueHS+49C7aIyOeAXFRzhnPiqS2XTD41E7i9sN9LVfxog1fu7hZy5xVvQu5e+VvOpnwLUIPc+eOHkXs17rXkOWuliEQBp4wx5/J4znagozGmGbmzk75+0bJGzhytgH8Dac71VgB3XrResHPyrVHABOdjLwHLjDENgZ+Aahetf7cxpgXQEhgtIuEAxphTQInzXyt1LR432ZgqdjoA3xtjcoBjIrKE3IbaAZhmjHEAR52TWhVWJSDxCstCga+d8xwZcuc3P2+Rcy72syKSDPzifHwTEHPRet9D7tzyIlLaOVdLJ3L/OGCMmS0ipy5af7SIDHB+XpXcIaUTzq+PA5Uv+lqpK9I9eFWcXGnWynRyZxnMy2vkNvJGwE2XrHfxHr/joq8d/HXn6dL5QK44P4iIdCH3ncp1zrsirb+kZqAzr1LXpA1eubs/gEGSexOJCHL3fFeTeyB1oHMsvgLQJR/bmgnc6RzXbwskG2OOkHsbxRpXeE4o/zd18fBCvobzxw06OGsmkzsd7BDn472B82fHhJI7XJQmIvXJvR0fzvUEqAjEFzKHKma0wSt39xMQB2wEFgL/zxhzlNx50A8BW4FvgXVAMoCIjHbOkhkJxDkPYkLu/QH2ArvJPWNmFIAxJhXYIyK186j/H+ANEVlP4Yc0M5zP/wQ4PxvlK0AnEdlC7lDNAefjvwF+IrINGEvuLR7PawGsvOj2j0pdlc4mqTyWiJQyxqQ4DzquBto7m39htjUAaGGM+VeRhixCIvI+MNMYs8DuLMoz6EFW5clmOQ9YBgCvFba5AxhjfvKAs1M2a3NXBaF78Eop5aV0DF4ppbyUNnillPJS2uCVUspLaYNXSikvpQ1eKaW81P8HIT4w0H032FcAAAAASUVORK5CYII=\n", - "text/plain": [ - "
    " - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": 9, + "id": "b1ea9e37", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", @@ -1896,132 +2433,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bbf679d3", + "metadata": { + "editable": true + }, "source": [ "## More examples on bootstrap and cross-validation and errors" ] }, { "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Degree of polynomial: 1\n", - "Mean squared error on training data: 446033.51374050\n", - "Mean squared error on test data: 455173.80460179\n", - "Degree of polynomial: 2\n", - "Mean squared error on training data: 114550.54637219\n", - "Mean squared error on test data: 129963.83146596\n", - "Degree of polynomial: 3\n", - "Mean squared error on training data: 9054.61775176\n", - "Mean squared error on test data: 10572.87627342\n", - "Degree of polynomial: 4\n", - "Mean squared error on training data: 302.15313054\n", - "Mean squared error on test data: 433.26292364\n", - "Degree of polynomial: 5\n", - "Mean squared error on training data: 3.64316192\n", - "Mean squared error on test data: 7.23528337\n", - "Degree of polynomial: 6\n", - "Mean squared error on training data: 3.56589683\n", - "Mean squared error on test data: 10.50427787\n", - "Degree of polynomial: 7\n", - "Mean squared error on training data: 0.47313680\n", - "Mean squared error on test data: 1.53738247\n", - "Degree of polynomial: 8\n", - "Mean squared error on training data: 0.04926746\n", - "Mean squared error on test data: 0.14629156\n", - "Degree of polynomial: 9\n", - "Mean squared error on training data: 0.02546675\n", - "Mean squared error on test data: 0.11202337\n", - "Degree of polynomial: 10\n", - "Mean squared error on training data: 0.02424794\n", - "Mean squared error on test data: 0.22467274\n", - "Degree of polynomial: 11\n", - "Mean squared error on training data: 0.01594452\n", - "Mean squared error on test data: 1.07641937\n", - "Degree of polynomial: 12\n", - "Mean squared error on training data: 0.00805074\n", - "Mean squared error on test data: 0.04295757\n", - "Degree of polynomial: 13\n", - "Mean squared error on training data: 0.00781918\n", - "Mean squared error on test data: 0.56965674\n", - "Degree of polynomial: 14\n", - "Mean squared error on training data: 0.00465099\n", - "Mean squared error on test data: 0.28443037\n", - "Degree of polynomial: 15\n", - "Mean squared error on training data: 0.00420072\n", - "Mean squared error on test data: 568.46764611\n", - "Degree of polynomial: 16\n", - "Mean squared error on training data: 0.00325450\n", - "Mean squared error on test data: 48.97816846\n", - "Degree of polynomial: 17\n", - "Mean squared error on training data: 0.00242954\n", - "Mean squared error on test data: 2.52781930\n", - "Degree of polynomial: 18\n", - "Mean squared error on training data: 0.00219194\n", - "Mean squared error on test data: 429.08472112\n", - "Degree of polynomial: 19\n", - "Mean squared error on training data: 0.00154858\n", - "Mean squared error on test data: 243.07381539\n", - "Degree of polynomial: 20\n", - "Mean squared error on training data: 0.00140907\n", - "Mean squared error on test data: 1345.82751541\n", - "Degree of polynomial: 21\n", - "Mean squared error on training data: 0.00119942\n", - "Mean squared error on test data: 1836.90791879\n", - "Degree of polynomial: 22\n", - "Mean squared error on training data: 0.00092941\n", - "Mean squared error on test data: 1186.40097146\n", - "Degree of polynomial: 23\n", - "Mean squared error on training data: 0.00089187\n", - "Mean squared error on test data: 3897.46661311\n", - "Degree of polynomial: 24\n", - "Mean squared error on training data: 0.00083294\n", - "Mean squared error on test data: 1373.69301339\n", - "Degree of polynomial: 25\n", - "Mean squared error on training data: 0.00079928\n", - "Mean squared error on test data: 7803.21490115\n", - "Degree of polynomial: 26\n", - "Mean squared error on training data: 0.00075608\n", - "Mean squared error on test data: 1099.96635131\n", - "Degree of polynomial: 27\n", - "Mean squared error on training data: 0.00068344\n", - "Mean squared error on test data: 3165.69836349\n", - "Degree of polynomial: 28\n", - "Mean squared error on training data: 0.00063301\n", - "Mean squared error on test data: 545.87095029\n", - "Degree of polynomial: 29\n", - "Mean squared error on training data: 0.00063870\n", - "Mean squared error on test data: 3115.85424414\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":73: RuntimeWarning: divide by zero encountered in log10\n", - " plt.plot(polynomial, np.log10(trainingerror), label='Training Error')\n", - ":74: RuntimeWarning: divide by zero encountered in log10\n", - " plt.plot(polynomial, np.log10(testerror),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UkSSsP/2/4ltwlIhTquPqibF+2V3iTHmOqdjCTQRifcuUp4CLAFGGGN+cDouFfz0ikA1GSLyb2ynq6/29GD1kbejORL4syYBFSh6RaCUUiFOO4uVUirEaSJQSqkQp4lAKaVCnCYCpZQKcZoIlFIqxGkiUEqpEPf/Ae1K/neJ7iLqAAAAAElFTkSuQmCC\n", - "text/plain": [ - "
    " - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": 10, + "id": "6ac512a1", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "# Common imports\n", "import os\n", @@ -2105,11 +2533,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "3f0f1bcd", + "metadata": { + "editable": true + }, + "source": [ + "Note that we kept the intercept column in the fitting here. This means that we need to set the **intercept** in the call to the **Scikit-Learn** function as **False**. Alternatively, we could have set up the design matrix $X$ without the first column of ones." + ] + }, + { + "cell_type": "markdown", + "id": "336fb423", + "metadata": { + "editable": true + }, "source": [ - "Note that we kept the intercept column in the fitting here. This means that we need to set the **intercept** in the call to the **Scikit-Learn** function as **False**. Alternatively, we could have set up the design matrix $X$ without the first column of ones.\n", - "\n", - "\n", "## The same example but now with cross-validation\n", "\n", "In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error." @@ -2117,30 +2555,13 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":63: RuntimeWarning: divide by zero encountered in log10\n", - " plt.plot(polynomial, np.log10(estimated_mse_sklearn), label='Test Error')\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEGCAYAAABsLkJ6AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAvfklEQVR4nO3dd3wUd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zRWSdiGy27qCalzvmD1ahwW8qjIRVPkwTgGp0rFomF+Ecwfl3YIsxZhDOUZzzym9rlfldAVxirZqGsx56ibUcYIwZCfwR58hdcF54jTFmIM5RoW+LSIj13gDgN8AI4EngpDFmKLAO+G0l4c4yxoyw7lqaAZe6OL23gHuNMYMrrL8NyDPGjLCO/TsR6WrFEgv0A27CWe+lvGyriOAy4DHgPGs5HnjASowvAVcbY4YDc6zzUooA15so1WCaWeVtwXkH8CbOcgRXARhjvheR1iLSosJ+bwAP4Sw3MR34Xbn3Thc224TzQgowDudFEWPMbhE5CPSy3ltuJZV8EckDPrPWJwC/uPuwTBSRh4BQnMPvd5bb5xes2i0R1rwCAO/gTHTgrP80qFy/QUugpxXrIqtwWbqILK/wsQusv0fhTBJrrJuQIJxJqzfOpLbUWu+PswKmUpoAVKNyyipve4aLFhUAjDFrrA7VcwB/Y0z5jtXTdVDKqNl/7+XrpjjKLTsq7m/dNbyCcya3FHHODhZC3QjOO4NvKhzD1XSFBeX2X2qMua7C/gOBncaYincOSmkTkGr0VgE3AFgX+KMVa9Vb5gHv42xiqc1n9sJZ7GxPHWI7fbE/arW3V/vUj1W2N9cqUsbpGCzfAHeV68voJc7KsGuAq6y+gHY4i89VZj0wVkR6WPuHWee2B4gSkdHW+kAR6V/L81RNlN4BqMbucWCOiGwHTvJzeeKK3gP+CcyvwWe+ArwqIglAKXCLMaaoJncb5RljckXkdZzlhNNxlit3ZTrO8zHAt+XWv4GziWqz1ZGchXM6vw+BSUAiztnwNgN5lcSSJSK3APNFJNha/ZgxZq/VrDRTRFri/H/+RZxNVcrHaTVQ1SRYF7krjDE32R2Lu4lIc2vy79bABmCsMSbd7riU99M7AOX1ROQlnJ2prtrLvdXnVgdyEPAPvfgrd9E7AKWU8lHaCayUUj5KE4BSSvkoTQBKKeWjNAEopZSP0gSglFI+6v8BGJYmwBdsB44AAAAASUVORK5CYII=\n", - "text/plain": [ - "
    " - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": 11, + "id": "811b0e58", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "# Common imports\n", "import os\n", @@ -2210,34 +2631,9 @@ "plt.legend()\n", "plt.show()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, + "metadata": {}, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 } diff --git a/doc/src/week37/olscode.py~ b/doc/src/week37/olscode.py~ deleted file mode 100644 index a6094b632..000000000 --- a/doc/src/week37/olscode.py~ +++ /dev/null @@ -1,47 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from sklearn.model_selection import KFold -from sklearn.linear_model import Ridge, LinearRegression -from sklearn.model_selection import cross_val_score -from sklearn.preprocessing import PolynomialFeatures - -# A seed just to ensure that the random numbers are the same for every run. -# Useful for eventual debugging. -np.random.seed(3155) - -# Generate the data. -nsamples = 1000 -x = np.random.randn(nsamples) -y = 3*x**2 + np.random.randn(nsamples) - -## Cross-validation on Ridge regression using KFold only - -# Decide degree on polynomial to fit -poly = PolynomialFeatures(degree = 6) - - -# Initialize a KFold instance -k = 10 -kfold = KFold(n_splits = k) - -# Perform the cross-validation to estimate MSE using OLS -scores_KFold = np.zeros((k)) -model = LinearRegression() -j = 0 -for train_inds, test_inds in kfold.split(x): - xtrain = x[train_inds] - ytrain = y[train_inds] - xtest = x[test_inds] - ytest = y[test_inds] - Xtrain = poly.fit_transform(xtrain[:, np.newaxis]) - model.fit(Xtrain, ytrain[:, np.newaxis]) - Xtest = poly.fit_transform(xtest[:, np.newaxis]) - ypred = model.predict(Xtest) - scores_KFold[j] = np.sum((ypred - ytest[:, np.newaxis])**2)/np.size(ypred) - print(f"Score for each fold:{scores_KFold[j]}") - j += 1 - - -estimated_mse_KFold = np.mean(scores_KFold) -print(f"Average OLS score:{estimated_mse_KFold}") - diff --git a/doc/src/week37/week37.do.txt b/doc/src/week37/week37.do.txt index c16dd66b7..3015c2a63 100644 --- a/doc/src/week37/week37.do.txt +++ b/doc/src/week37/week37.do.txt @@ -5,11 +5,9 @@ DATE: today !split ===== Plans for week 37 ===== -* Thursday September 16: Summary of Ridge and Lasso with examples and start resampling techniques - o "Video of Lecture, first part":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember16Firstpart.mp4?vrtx=view-as-webpage" - o "Video of Lecture, second part":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember16SecondPart.mp4?vrtx=view-as-webpage" -* Friday September 17: Resampling methods, Cross-validation, Bootstrapping and jackknife - o "Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember17.mp4?vrtx=view-as-webpage" +* Thursday September 15: Summary of Ridge and Lasso with examples and start resampling techniques +* Friday September 16: Resampling methods, Cross-validation, Bootstrapping and jackknife + Recommended Reading: o Lectures on Resampling methods (these lectures) o Bishop 1.3 (cross-validation) and 3.2 (bias-variance tradeoff) @@ -18,7 +16,7 @@ o Hastie et al Chapter 7, here we recommend 7.1-7.5 and 7.10 (cross-validation) !split -===== Thursday September 16, Summary of Ridge and Lasso Regression and start Resampling methods ===== +===== Thursday September 15, Summary of Ridge and Lasso Regression and start Resampling methods ===== !split