From 61f5aed38a46a08563e8b46dcaa00a4028568238 Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Sun, 12 Sep 2021 21:38:37 +0200 Subject: [PATCH] updated week 36 --- doc/pub/week36/html/._week36-bs000.html | 102 ++--- doc/pub/week36/html/._week36-bs001.html | 100 ++--- doc/pub/week36/html/._week36-bs002.html | 100 ++--- doc/pub/week36/html/._week36-bs003.html | 100 ++--- doc/pub/week36/html/._week36-bs004.html | 100 ++--- doc/pub/week36/html/._week36-bs005.html | 100 ++--- doc/pub/week36/html/._week36-bs006.html | 100 ++--- doc/pub/week36/html/._week36-bs007.html | 100 ++--- doc/pub/week36/html/._week36-bs008.html | 100 ++--- doc/pub/week36/html/._week36-bs009.html | 100 ++--- doc/pub/week36/html/._week36-bs010.html | 100 ++--- doc/pub/week36/html/._week36-bs011.html | 100 ++--- doc/pub/week36/html/._week36-bs012.html | 100 ++--- doc/pub/week36/html/._week36-bs013.html | 100 ++--- doc/pub/week36/html/._week36-bs014.html | 100 ++--- doc/pub/week36/html/._week36-bs015.html | 100 ++--- doc/pub/week36/html/._week36-bs016.html | 100 ++--- doc/pub/week36/html/._week36-bs017.html | 100 ++--- doc/pub/week36/html/._week36-bs018.html | 100 ++--- doc/pub/week36/html/._week36-bs019.html | 100 ++--- doc/pub/week36/html/._week36-bs020.html | 100 ++--- doc/pub/week36/html/._week36-bs021.html | 100 ++--- doc/pub/week36/html/._week36-bs022.html | 100 ++--- doc/pub/week36/html/._week36-bs023.html | 100 ++--- doc/pub/week36/html/._week36-bs024.html | 100 ++--- doc/pub/week36/html/._week36-bs025.html | 100 ++--- doc/pub/week36/html/._week36-bs026.html | 100 ++--- doc/pub/week36/html/._week36-bs027.html | 100 ++--- doc/pub/week36/html/._week36-bs028.html | 380 ++++++++++++++++--- doc/pub/week36/html/._week36-bs029.html | 145 +++---- doc/pub/week36/html/._week36-bs030.html | 148 +++++--- doc/pub/week36/html/._week36-bs031.html | 133 +++---- doc/pub/week36/html/._week36-bs032.html | 195 ++++------ doc/pub/week36/html/._week36-bs033.html | 186 ++++++--- doc/pub/week36/html/._week36-bs034.html | 139 ++++--- doc/pub/week36/html/._week36-bs035.html | 143 +++---- doc/pub/week36/html/._week36-bs036.html | 142 +++---- doc/pub/week36/html/._week36-bs037.html | 151 ++++---- doc/pub/week36/html/._week36-bs038.html | 132 ++++--- doc/pub/week36/html/._week36-bs039.html | 106 +++--- doc/pub/week36/html/._week36-bs040.html | 118 +++--- doc/pub/week36/html/._week36-bs041.html | 120 +++--- doc/pub/week36/html/._week36-bs042.html | 124 +++--- doc/pub/week36/html/._week36-bs043.html | 133 +++---- doc/pub/week36/html/._week36-bs044.html | 126 +++--- doc/pub/week36/html/._week36-bs045.html | 183 +++------ doc/pub/week36/html/._week36-bs046.html | 194 ++++++---- doc/pub/week36/html/._week36-bs047.html | 138 ++++--- doc/pub/week36/html/._week36-bs048.html | 126 +++--- doc/pub/week36/html/._week36-bs049.html | 136 ++++--- doc/pub/week36/html/._week36-bs050.html | 131 +++---- doc/pub/week36/html/._week36-bs051.html | 136 +++---- doc/pub/week36/html/._week36-bs052.html | 125 +++--- doc/pub/week36/html/._week36-bs053.html | 114 +++--- doc/pub/week36/html/._week36-bs054.html | 136 ++++--- doc/pub/week36/html/._week36-bs055.html | 132 ++++--- doc/pub/week36/html/._week36-bs056.html | 126 +++--- doc/pub/week36/html/._week36-bs057.html | 143 ++++--- doc/pub/week36/html/._week36-bs058.html | 146 +++---- doc/pub/week36/html/._week36-bs059.html | 128 ++++--- doc/pub/week36/html/._week36-bs060.html | 126 +++--- doc/pub/week36/html/._week36-bs061.html | 129 ++++--- doc/pub/week36/html/._week36-bs062.html | 132 ++++--- doc/pub/week36/html/._week36-bs063.html | 173 ++++----- doc/pub/week36/html/._week36-bs064.html | 175 +++++---- doc/pub/week36/html/._week36-bs065.html | 143 ++++--- doc/pub/week36/html/._week36-bs066.html | 148 ++++---- doc/pub/week36/html/._week36-bs067.html | 205 ++++------ doc/pub/week36/html/._week36-bs068.html | 231 ++++++----- doc/pub/week36/html/._week36-bs069.html | 199 +++++----- doc/pub/week36/html/._week36-bs070.html | 163 ++++---- doc/pub/week36/html/._week36-bs071.html | 176 +++++---- doc/pub/week36/html/._week36-bs072.html | 201 ++++------ doc/pub/week36/html/._week36-bs073.html | 227 ++++++----- doc/pub/week36/html/._week36-bs074.html | 140 ++++--- doc/pub/week36/html/._week36-bs075.html | 192 ++++++---- doc/pub/week36/html/week36-bs.html | 102 ++--- doc/pub/week36/html/week36-reveal.html | 286 +++++++++++++- doc/pub/week36/html/week36-solarized.html | 286 +++++++++++++- doc/pub/week36/html/week36.html | 286 +++++++++++++- doc/pub/week36/ipynb/ipynb-week36-src.tar.gz | Bin 192 -> 191 bytes doc/pub/week36/ipynb/week36.ipynb | 294 +++++++++++++- doc/src/week36/week36.do.txt | 281 ++++++++++++++ 83 files changed, 6821 insertions(+), 4991 deletions(-) diff --git a/doc/pub/week36/html/._week36-bs000.html b/doc/pub/week36/html/._week36-bs000.html index b7fdad551..6ae16d98c 100644 --- a/doc/pub/week36/html/._week36-bs000.html +++ b/doc/pub/week36/html/._week36-bs000.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -400,7 +402,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 10, 2021

    +

    Sep 12, 2021


    @@ -424,7 +426,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs001.html b/doc/pub/week36/html/._week36-bs001.html index 2ae34b714..eb7b9ac9d 100644 --- a/doc/pub/week36/html/._week36-bs001.html +++ b/doc/pub/week36/html/._week36-bs001.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -412,7 +414,7 @@ Recommended Reading:
  • 10
  • 11
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs002.html b/doc/pub/week36/html/._week36-bs002.html index 5744fea8c..7619d2977 100644 --- a/doc/pub/week36/html/._week36-bs002.html +++ b/doc/pub/week36/html/._week36-bs002.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -401,7 +403,7 @@ MathJax.Hub.Config({
  • 11
  • 12
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs003.html b/doc/pub/week36/html/._week36-bs003.html index a621bd94e..00bff815a 100644 --- a/doc/pub/week36/html/._week36-bs003.html +++ b/doc/pub/week36/html/._week36-bs003.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -402,7 +404,7 @@ MathJax.Hub.Config({
  • 12
  • 13
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs004.html b/doc/pub/week36/html/._week36-bs004.html index 3e568c489..cae3f48b5 100644 --- a/doc/pub/week36/html/._week36-bs004.html +++ b/doc/pub/week36/html/._week36-bs004.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -435,7 +437,7 @@ $$
  • 13
  • 14
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs005.html b/doc/pub/week36/html/._week36-bs005.html index 307be260c..6b945396a 100644 --- a/doc/pub/week36/html/._week36-bs005.html +++ b/doc/pub/week36/html/._week36-bs005.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -442,7 +444,7 @@ absolute value of the eigenvalues of \( \boldsymbol{X} \).
  • 14
  • 15
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs006.html b/doc/pub/week36/html/._week36-bs006.html index 036586223..2e0fe2eb4 100644 --- a/doc/pub/week36/html/._week36-bs006.html +++ b/doc/pub/week36/html/._week36-bs006.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -439,7 +441,7 @@ values and the column vectors of \( \boldsymbol{V} \).
  • 15
  • 16
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs007.html b/doc/pub/week36/html/._week36-bs007.html index 1961cdcce..18985c08d 100644 --- a/doc/pub/week36/html/._week36-bs007.html +++ b/doc/pub/week36/html/._week36-bs007.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -450,7 +452,7 @@ C = SVDinv(A)
  • 16
  • 17
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs008.html b/doc/pub/week36/html/._week36-bs008.html index d6c9ccd4a..e32acb789 100644 --- a/doc/pub/week36/html/._week36-bs008.html +++ b/doc/pub/week36/html/._week36-bs008.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -456,7 +458,7 @@ As you can see from this example, our own decomposition based on the SVD agrees
  • 17
  • 18
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs009.html b/doc/pub/week36/html/._week36-bs009.html index 15240a2b2..d8e4a9e86 100644 --- a/doc/pub/week36/html/._week36-bs009.html +++ b/doc/pub/week36/html/._week36-bs009.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -426,7 +428,7 @@ $$
  • 18
  • 19
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs010.html b/doc/pub/week36/html/._week36-bs010.html index 001ae8a49..628aaaa36 100644 --- a/doc/pub/week36/html/._week36-bs010.html +++ b/doc/pub/week36/html/._week36-bs010.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -444,7 +446,7 @@ $$
  • 19
  • 20
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs011.html b/doc/pub/week36/html/._week36-bs011.html index d22ff157b..644e11479 100644 --- a/doc/pub/week36/html/._week36-bs011.html +++ b/doc/pub/week36/html/._week36-bs011.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -450,7 +452,7 @@ even reduce the variance of the optimal parameters \( \boldsymbol{\beta} \). The
  • 20
  • 21
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs012.html b/doc/pub/week36/html/._week36-bs012.html index 5920f562c..338d47a29 100644 --- a/doc/pub/week36/html/._week36-bs012.html +++ b/doc/pub/week36/html/._week36-bs012.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -426,7 +428,7 @@ with the vectors \( \boldsymbol{u}_j \) being the columns of \( \boldsymbol{U} \
  • 21
  • 22
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs013.html b/doc/pub/week36/html/._week36-bs013.html index 1aa1ec6f9..9b3b282a7 100644 --- a/doc/pub/week36/html/._week36-bs013.html +++ b/doc/pub/week36/html/._week36-bs013.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -426,7 +428,7 @@ For small eigenvalues \( \sigma_i \) it means that their contributions become le
  • 22
  • 23
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs014.html b/doc/pub/week36/html/._week36-bs014.html index 53dc2f2cb..c5137f61d 100644 --- a/doc/pub/week36/html/._week36-bs014.html +++ b/doc/pub/week36/html/._week36-bs014.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -441,7 +443,7 @@ Similarly, Mehta et al
  • 23
  • 24
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs015.html b/doc/pub/week36/html/._week36-bs015.html index 0066c9cac..a679d48d0 100644 --- a/doc/pub/week36/html/._week36-bs015.html +++ b/doc/pub/week36/html/._week36-bs015.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -435,7 +437,7 @@ This equation does not lead to a nice analytical equation as in Ridge regression
  • 24
  • 25
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs016.html b/doc/pub/week36/html/._week36-bs016.html index e54034c6c..5774cf409 100644 --- a/doc/pub/week36/html/._week36-bs016.html +++ b/doc/pub/week36/html/._week36-bs016.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -424,7 +426,7 @@ $$
  • 25
  • 26
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs017.html b/doc/pub/week36/html/._week36-bs017.html index b8a875cda..027848fec 100644 --- a/doc/pub/week36/html/._week36-bs017.html +++ b/doc/pub/week36/html/._week36-bs017.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -420,7 +422,7 @@ $$
  • 26
  • 27
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs018.html b/doc/pub/week36/html/._week36-bs018.html index 69ea86e69..7bff8e466 100644 --- a/doc/pub/week36/html/._week36-bs018.html +++ b/doc/pub/week36/html/._week36-bs018.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -430,7 +432,7 @@ Plotting these results (27
  • 28
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs019.html b/doc/pub/week36/html/._week36-bs019.html index a7c2710a2..78b03b4c2 100644 --- a/doc/pub/week36/html/._week36-bs019.html +++ b/doc/pub/week36/html/._week36-bs019.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -423,7 +425,7 @@ meaning that we have two features and two unknown parameters \( \beta_0 \) and \
  • 28
  • 29
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs020.html b/doc/pub/week36/html/._week36-bs020.html index 466079c18..5993a5ede 100644 --- a/doc/pub/week36/html/._week36-bs020.html +++ b/doc/pub/week36/html/._week36-bs020.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -425,7 +427,7 @@ The code which implements this simpler case is presented after the discussion of
  • 29
  • 30
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs021.html b/doc/pub/week36/html/._week36-bs021.html index 56ee2ccc6..0b2c8b7e1 100644 --- a/doc/pub/week36/html/._week36-bs021.html +++ b/doc/pub/week36/html/._week36-bs021.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -429,7 +431,7 @@ To see this, let us write the cost function for Ridge regression.
  • 30
  • 31
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs022.html b/doc/pub/week36/html/._week36-bs022.html index 4a39d201e..ef0e7f304 100644 --- a/doc/pub/week36/html/._week36-bs022.html +++ b/doc/pub/week36/html/._week36-bs022.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -438,7 +440,7 @@ which gives \( \lambda=4.571 \) and \( \beta_0=0.933 \) and \( \beta_1=0.359 \).
  • 31
  • 32
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs023.html b/doc/pub/week36/html/._week36-bs023.html index 989fd1bb7..f2d7f583f 100644 --- a/doc/pub/week36/html/._week36-bs023.html +++ b/doc/pub/week36/html/._week36-bs023.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -434,7 +436,7 @@ We have now four cases to solve besides the trivial cases \( \beta_0 \) and/or \
  • 32
  • 33
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs024.html b/doc/pub/week36/html/._week36-bs024.html index 506d4f0f6..1eaf8d171 100644 --- a/doc/pub/week36/html/._week36-bs024.html +++ b/doc/pub/week36/html/._week36-bs024.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -434,7 +436,7 @@ Using the constraint on \( \beta_0 \) and \( \beta_1 \) we can then find the opt
  • 33
  • 34
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs025.html b/doc/pub/week36/html/._week36-bs025.html index 79c514d1e..405273cf2 100644 --- a/doc/pub/week36/html/._week36-bs025.html +++ b/doc/pub/week36/html/._week36-bs025.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -471,7 +473,7 @@ We see here that we reach a plateau. What is actually happening?
  • 34
  • 35
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs026.html b/doc/pub/week36/html/._week36-bs026.html index 60a60bc4e..16698887b 100644 --- a/doc/pub/week36/html/._week36-bs026.html +++ b/doc/pub/week36/html/._week36-bs026.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -469,7 +471,7 @@ plt.show()
  • 35
  • 36
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs027.html b/doc/pub/week36/html/._week36-bs027.html index afc97f721..1cf40c99d 100644 --- a/doc/pub/week36/html/._week36-bs027.html +++ b/doc/pub/week36/html/._week36-bs027.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -491,7 +493,7 @@ plt.show()
  • 36
  • 37
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs028.html b/doc/pub/week36/html/._week36-bs028.html index b0f98248e..386a6de2d 100644 --- a/doc/pub/week36/html/._week36-bs028.html +++ b/doc/pub/week36/html/._week36-bs028.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,8 +383,286 @@ MathJax.Hub.Config({ -

    Friday September 10

    +

    Using CVXOPT

    +

    +As a small addendum, we note that you can also solve this problem +using the convex optimization package +CVXOPT. This +requires, in addition to having installed CVXOPT, you need to +download the file l1regl.py. The following code example solves the +simpler problem we discussed above, where we have added the latter +python file. + +

    + + +

    from l1regls import l1regls
    +from cvxopt import matrix, normal
    +import numpy as np
    +
    +X = matrix( [ [ 2, 0, 1], [0, 1, 3]])
    +y = matrix( [4, 2, 3])
    +x = l1regls(X,y)
    +
    +from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed
    +from cvxopt import blas, lapack, solvers, sparse, spmatrix
    +import math
    +
    +try:
    +    import mosek
    +    import sys
    +    __MOSEK = True
    +except: __MOSEK = False
    +
    +if __MOSEK:
    +
    +    def l1regls_mosek(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize    || A*x - b ||_2^2  + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars( 2*n)            # number of variables
    +        task.appendcons( 2*n)            # number of constraints
    +
    +        # input quadratic objective
    +        Q = matrix(0.0, (n,n)) 
    +        blas.syrk(A, Q, alpha = 2.0, trans='T')
    +
    +        I = []
    +        for i in range(n):
    +            I.extend(range(i,n))
    +
    +        J = []
    +        for i in range(n):
    +            J.extend((n-i)*[i])
    +
    +        task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n]))
    +        task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var,
    +                           0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +    def l1regls_mosek2(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize     w'*w + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +                         A*x - w = b
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars(2*n + m)     # number of variables
    +        task.appendcons(2*n + m)     # number of constraints
    +
    +        # input quadratic objective
    +        task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0])
    +
    +        task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        for i in range(m):
    +            task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b))
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], 
    +                           (2*n+m)*[0.0], (2*n+m)*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +def l1regls(A, b):
    +    """
    +    
    +    Returns the solution of l1-norm regularized least-squares problem
    +  
    +        minimize || A*x - b ||_2^2  + || x ||_1.
    +
    +    """
    +
    +    m, n = A.size
    +    q = matrix(1.0, (2*n,1))
    +    q[:n] = -2.0 * A.T * b
    +
    +    def P(u, v, alpha = 1.0, beta = 0.0 ):
    +        """
    +            v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v 
    +        """
    +        v *= beta
    +        v[:n] += alpha * 2.0 * A.T * (A * u[:n])
    +
    +
    +    def G(u, v, alpha=1.0, beta=0.0, trans='N'):
    +        """
    +            v := alpha*[I, -I; -I, -I] * u + beta * v  (trans = 'N' or 'T')
    +        """
    +
    +        v *= beta
    +        v[:n] += alpha*(u[:n] - u[n:])
    +        v[n:] += alpha*(-u[:n] - u[n:])
    +
    +    h = matrix(0.0, (2*n,1))
    +
    +
    +    # Customized solver for the KKT system 
    +    #
    +    #     [  2.0*A'*A  0    I      -I     ] [x[:n] ]     [bx[:n] ]
    +    #     [  0         0   -I      -I     ] [x[n:] ]  =  [bx[n:] ].
    +    #     [  I        -I   -D1^-1   0     ] [zl[:n]]     [bzl[:n]]
    +    #     [ -I        -I    0      -D2^-1 ] [zl[n:]]     [bzl[n:]]
    +    #
    +    # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2.
    +    #    
    +    # We first eliminate zl and x[n:]:
    +    #
    +    #     ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = 
    +    #         bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +    #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +    #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:]           
    +    #
    +    #     x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +    #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +    #
    +    #     zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] )
    +    #     zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ).
    +    #
    +    # The first equation has the form
    +    #
    +    #     (A'*A + D)*x[:n]  =  rhs
    +    #
    +    # and is equivalent to
    +    #
    +    #     [ D    A' ] [ x:n] ]  = [ rhs ]
    +    #     [ A   -I  ] [ v    ]    [ 0   ].
    +    #
    +    # It can be solved as 
    +    #
    +    #     ( A*D^-1*A' + I ) * v = A * D^-1 * rhs
    +    #     x[:n] = D^-1 * ( rhs - A'*v ).
    +
    +    S = matrix(0.0, (m,m))
    +    Asc = matrix(0.0, (m,n))
    +    v = matrix(0.0, (m,1))
    +
    +    def Fkkt(W):
    +
    +        # Factor 
    +        #
    +        #     S = A*D^-1*A' + I 
    +        #
    +        # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2.
    +
    +        d1, d2 = W['di'][:n]**2, W['di'][n:]**2
    +
    +        # ds is square root of diagonal of D
    +        ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), 
    +            sqrt(d1+d2) )
    +        d3 =  div(d2 - d1, d1 + d2)
    +     
    +        # Asc = A*diag(d)^-1/2
    +        Asc = A * spdiag(ds**-1)
    +
    +        # S = I + A * D^-1 * A'
    +        blas.syrk(Asc, S)
    +        S[::m+1] += 1.0 
    +        lapack.potrf(S)
    +
    +        def g(x, y, z):
    +
    +            x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + 
    +                mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - 
    +                mul(d3, z[n:])) )
    +            x[:n] = div( x[:n], ds) 
    +
    +            # Solve
    +            #
    +            #     S * v = 0.5 * A * D^-1 * ( bx[:n] - 
    +            #         (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +            #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +            #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] )
    +                
    +            blas.gemv(Asc, x, v)
    +            lapack.potrs(S, v)
    +            
    +            # x[:n] = D^-1 * ( rhs - A'*v ).
    +            blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')
    +            x[:n] = div(x[:n], ds)
    +
    +            # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +            #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +            x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\
    +                - mul( d3, x[:n] )
    +                
    +            # zl[:n] = D1^1/2 * (  x[:n] - x[n:] - bzl[:n] )
    +            # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ).
    +            z[:n] = mul( W['di'][:n],  x[:n] - x[n:] - z[:n] ) 
    +            z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) 
    +
    +        return g
    +
    +    return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n]
    +

    @@ -409,7 +689,7 @@ MathJax.Hub.Config({

  • 37
  • 38
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs029.html b/doc/pub/week36/html/._week36-bs029.html index ebc7550a1..55939e6b8 100644 --- a/doc/pub/week36/html/._week36-bs029.html +++ b/doc/pub/week36/html/._week36-bs029.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,50 +381,9 @@ MathJax.Hub.Config({

     

     

     

    - + -

    Linking the regression analysis with a statistical interpretation

    - -

    -We will now couple the discussions of ordinary least squares, Ridge -and Lasso regression with a statistical interpretation, that is we -move from a linear algebra analysis to a statistical analysis. In -particular, we will focus on what the regularization terms can result -in. We will amongst other things show that the regularization -parameter can reduce considerably the variance of the parameters -\( \beta \). - -

    -The -advantage of doing linear regression is that we actually end up with -analytical expressions for several statistical quantities. -Standard least squares and Ridge regression allow us to -derive quantities like the variance and other expectation values in a -rather straightforward way. - -

    -It is assumed that \( \varepsilon_i -\sim \mathcal{N}(0, \sigma^2) \) and the \( \varepsilon_{i} \) are -independent, i.e.: -$$ -\begin{align*} -\mbox{Cov}(\varepsilon_{i_1}, -\varepsilon_{i_2}) & = \left\{ \begin{array}{lcc} \sigma^2 & \mbox{if} -& i_1 = i_2, \\ 0 & \mbox{if} & i_1 \not= i_2. \end{array} \right. -\end{align*} -$$ - -The randomness of \( \varepsilon_i \) implies that -\( \mathbf{y}_i \) is also a random variable. In particular, -\( \mathbf{y}_i \) is normally distributed, because \( \varepsilon_i \sim -\mathcal{N}(0, \sigma^2) \) and \( \mathbf{X}_{i,\ast} \, \boldsymbol{\beta} \) is a -non-random scalar. To specify the parameters of the distribution of -\( \mathbf{y}_i \) we need to calculate its first two moments. - -

    -Recall that \( \boldsymbol{X} \) is a matrix of dimensionality \( n\times p \). The -notation above \( \mathbf{X}_{i,\ast} \) means that we are looking at the -row number \( i \) and perform a sum over all values \( p \). +

    Friday September 10

    @@ -450,7 +411,7 @@ row number \( i \) and perform a sum over all values \( p \).

  • 38
  • 39
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs030.html b/doc/pub/week36/html/._week36-bs030.html index 57d01ad1b..eb7d4b002 100644 --- a/doc/pub/week36/html/._week36-bs030.html +++ b/doc/pub/week36/html/._week36-bs030.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,25 +381,51 @@ MathJax.Hub.Config({

     

     

     

    - + -

    Assumptions made

    +

    Linking the regression analysis with a statistical interpretation

    -The assumption we have made here can be summarized as (and this is going to be useful when we discuss the bias-variance trade off) -that there exists a function \( f(\boldsymbol{x}) \) and a normal distributed error \( \boldsymbol{\varepsilon}\sim \mathcal{N}(0, \sigma^2) \) -which describe our data -$$ -\boldsymbol{y} = f(\boldsymbol{x})+\boldsymbol{\varepsilon} -$$ +We will now couple the discussions of ordinary least squares, Ridge +and Lasso regression with a statistical interpretation, that is we +move from a linear algebra analysis to a statistical analysis. In +particular, we will focus on what the regularization terms can result +in. We will amongst other things show that the regularization +parameter can reduce considerably the variance of the parameters +\( \beta \).

    -We approximate this function with our model from the solution of the linear regression equations, that is our -function \( f \) is approximated by \( \boldsymbol{\tilde{y}} \) where we want to minimize \( (\boldsymbol{y}-\boldsymbol{\tilde{y}})^2 \), our MSE, with +The +advantage of doing linear regression is that we actually end up with +analytical expressions for several statistical quantities. +Standard least squares and Ridge regression allow us to +derive quantities like the variance and other expectation values in a +rather straightforward way. + +

    +It is assumed that \( \varepsilon_i +\sim \mathcal{N}(0, \sigma^2) \) and the \( \varepsilon_{i} \) are +independent, i.e.: $$ -\boldsymbol{\tilde{y}} = \boldsymbol{X}\boldsymbol{\beta}. +\begin{align*} +\mbox{Cov}(\varepsilon_{i_1}, +\varepsilon_{i_2}) & = \left\{ \begin{array}{lcc} \sigma^2 & \mbox{if} +& i_1 = i_2, \\ 0 & \mbox{if} & i_1 \not= i_2. \end{array} \right. +\end{align*} $$ +The randomness of \( \varepsilon_i \) implies that +\( \mathbf{y}_i \) is also a random variable. In particular, +\( \mathbf{y}_i \) is normally distributed, because \( \varepsilon_i \sim +\mathcal{N}(0, \sigma^2) \) and \( \mathbf{X}_{i,\ast} \, \boldsymbol{\beta} \) is a +non-random scalar. To specify the parameters of the distribution of +\( \mathbf{y}_i \) we need to calculate its first two moments. + +

    +Recall that \( \boldsymbol{X} \) is a matrix of dimensionality \( n\times p \). The +notation above \( \mathbf{X}_{i,\ast} \) means that we are looking at the +row number \( i \) and perform a sum over all values \( p \). +

    @@ -424,7 +452,7 @@ $$

  • 39
  • 40
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs031.html b/doc/pub/week36/html/._week36-bs031.html index 6324200d9..f3d1572c4 100644 --- a/doc/pub/week36/html/._week36-bs031.html +++ b/doc/pub/week36/html/._week36-bs031.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,38 +383,23 @@ MathJax.Hub.Config({ -

    Expectation value and variance

    +

    Assumptions made

    -We can calculate the expectation value of \( \boldsymbol{y} \) for a given element \( i \) +The assumption we have made here can be summarized as (and this is going to be useful when we discuss the bias-variance trade off) +that there exists a function \( f(\boldsymbol{x}) \) and a normal distributed error \( \boldsymbol{\varepsilon}\sim \mathcal{N}(0, \sigma^2) \) +which describe our data $$ -\begin{align*} -\mathbb{E}(y_i) & = -\mathbb{E}(\mathbf{X}_{i, \ast} \, \boldsymbol{\beta}) + \mathbb{E}(\varepsilon_i) -\, \, \, = \, \, \, \mathbf{X}_{i, \ast} \, \beta, -\end{align*} +\boldsymbol{y} = f(\boldsymbol{x})+\boldsymbol{\varepsilon} $$ -while -its variance is +

    +We approximate this function with our model from the solution of the linear regression equations, that is our +function \( f \) is approximated by \( \boldsymbol{\tilde{y}} \) where we want to minimize \( (\boldsymbol{y}-\boldsymbol{\tilde{y}})^2 \), our MSE, with $$ -\begin{align*} \mbox{Var}(y_i) & = \mathbb{E} \{ [y_i -- \mathbb{E}(y_i)]^2 \} \, \, \, = \, \, \, \mathbb{E} ( y_i^2 ) - -[\mathbb{E}(y_i)]^2 \\ & = \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, -\beta + \varepsilon_i )^2] - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 \\ & -= \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2 \varepsilon_i -\mathbf{X}_{i, \ast} \, \boldsymbol{\beta} + \varepsilon_i^2 ] - ( \mathbf{X}_{i, -\ast} \, \beta)^2 \\ & = ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2 -\mathbb{E}(\varepsilon_i) \mathbf{X}_{i, \ast} \, \boldsymbol{\beta} + -\mathbb{E}(\varepsilon_i^2 ) - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 -\\ & = \mathbb{E}(\varepsilon_i^2 ) \, \, \, = \, \, \, -\mbox{Var}(\varepsilon_i) \, \, \, = \, \, \, \sigma^2. -\end{align*} +\boldsymbol{\tilde{y}} = \boldsymbol{X}\boldsymbol{\beta}. $$ -Hence, \( y_i \sim \mathcal{N}( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta}, \sigma^2) \), that is \( \boldsymbol{y} \) follows a normal distribution with -mean value \( \boldsymbol{X}\boldsymbol{\beta} \) and variance \( \sigma^2 \) (not be confused with the singular values of the SVD). -

    @@ -439,7 +426,7 @@ mean value \( \boldsymbol{X}\boldsymbol{\beta} \) and variance \( \sigma^2 \) (n

  • 40
  • 41
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs032.html b/doc/pub/week36/html/._week36-bs032.html index 4ed0a91ab..544407fd4 100644 --- a/doc/pub/week36/html/._week36-bs032.html +++ b/doc/pub/week36/html/._week36-bs032.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,86 +383,37 @@ MathJax.Hub.Config({ -

    Expectation value and variance for \( \boldsymbol{\beta} \)

    +

    Expectation value and variance

    -With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we can evaluate the expectation value +We can calculate the expectation value of \( \boldsymbol{y} \) for a given element \( i \) $$ -\mathbb{E}(\boldsymbol{\beta}) = \mathbb{E}[ (\mathbf{X}^{\top} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbb{E}[ \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1} \mathbf{X}^{T}\mathbf{X}\boldsymbol{\beta}=\boldsymbol{\beta}. +\begin{align*} +\mathbb{E}(y_i) & = +\mathbb{E}(\mathbf{X}_{i, \ast} \, \boldsymbol{\beta}) + \mathbb{E}(\varepsilon_i) +\, \, \, = \, \, \, \mathbf{X}_{i, \ast} \, \beta, +\end{align*} $$ -This means that the estimator of the regression parameters is unbiased. - -

    -We can also calculate the variance - -

    -The variance of \( \boldsymbol{\beta} \) is +while +its variance is $$ -\begin{eqnarray*} -\mbox{Var}(\boldsymbol{\beta}) & = & \mathbb{E} \{ [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})] [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})]^{T} \} -\\ -& = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \boldsymbol{\beta}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \boldsymbol{\beta}]^{T} \} -\\ -% & = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}]^{T} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} -% \\ -% & = & \mathbb{E} \{ (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} \, \mathbf{Y}^{T} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} -% \\ -& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \mathbb{E} \{ \mathbf{Y} \, \mathbf{Y}^{T} \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} -\\ -& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \{ \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} \, \mathbf{X}^{T} + \sigma^2 \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} -% \\ -% & = & (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^T \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T % \mathbf{X})^{-1} -% \\ -% & & + \, \, \sigma^2 \, (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T \mathbf{X})^{-1} - \boldsymbol{\beta} \boldsymbol{\beta}^T -\\ -& = & \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} + \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} -\, \, \, = \, \, \, \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1}, -\end{eqnarray*} +\begin{align*} \mbox{Var}(y_i) & = \mathbb{E} \{ [y_i +- \mathbb{E}(y_i)]^2 \} \, \, \, = \, \, \, \mathbb{E} ( y_i^2 ) - +[\mathbb{E}(y_i)]^2 \\ & = \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, +\beta + \varepsilon_i )^2] - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 \\ & += \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2 \varepsilon_i +\mathbf{X}_{i, \ast} \, \boldsymbol{\beta} + \varepsilon_i^2 ] - ( \mathbf{X}_{i, +\ast} \, \beta)^2 \\ & = ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 + 2 +\mathbb{E}(\varepsilon_i) \mathbf{X}_{i, \ast} \, \boldsymbol{\beta} + +\mathbb{E}(\varepsilon_i^2 ) - ( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta})^2 +\\ & = \mathbb{E}(\varepsilon_i^2 ) \, \, \, = \, \, \, +\mbox{Var}(\varepsilon_i) \, \, \, = \, \, \, \sigma^2. +\end{align*} $$ -

    -where we have used that \( \mathbb{E} (\mathbf{Y} \mathbf{Y}^{T}) = -\mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} \, \mathbf{X}^{T} + -\sigma^2 \, \mathbf{I}_{nn} \). From \( \mbox{Var}(\boldsymbol{\beta}) = \sigma^2 -\, (\mathbf{X}^{T} \mathbf{X})^{-1} \), one obtains an estimate of the -variance of the estimate of the \( j \)-th regression coefficient: -\( \boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} \). This may be used to -construct a confidence interval for the estimates. - -

    -In a similar way, we can obtain analytical expressions for say the -expectation values of the parameters \( \boldsymbol{\beta} \) and their variance -when we employ Ridge regression, allowing us again to define a confidence interval. - -

    -It is rather straightforward to show that -$$ -\mathbb{E} \big[ \boldsymbol{\beta}^{\mathrm{Ridge}} \big]=(\mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I}_{pp})^{-1} (\mathbf{X}^{\top} \mathbf{X})\boldsymbol{\beta}^{\mathrm{OLS}}. -$$ - -We see clearly that -\( \mathbb{E} \big[ \boldsymbol{\beta}^{\mathrm{Ridge}} \big] \not= \boldsymbol{\beta}^{\mathrm{OLS}} \) for any \( \lambda > 0 \). We say then that the ridge estimator is biased. - -

    -We can also compute the variance as - -$$ -\mbox{Var}[\boldsymbol{\beta}^{\mathrm{Ridge}}]=\sigma^2[ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1} \mathbf{X}^{T} \mathbf{X} \{ [ \mathbf{X}^{\top} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}, -$$ - -and it is easy to see that if the parameter \( \lambda \) goes to infinity then the variance of Ridge parameters \( \boldsymbol{\beta} \) goes to zero. - -

    -With this, we can compute the difference - -$$ -\mbox{Var}[\boldsymbol{\beta}^{\mathrm{OLS}}]-\mbox{Var}(\boldsymbol{\beta}^{\mathrm{Ridge}})=\sigma^2 [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}[ 2\lambda\mathbf{I} + \lambda^2 (\mathbf{X}^{T} \mathbf{X})^{-1} ] \{ [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}. -$$ - -The difference is non-negative definite since each component of the -matrix product is non-negative definite. -This means the variance we obtain with the standard OLS will always for \( \lambda > 0 \) be larger than the variance of \( \boldsymbol{\beta} \) obtained with the Ridge estimator. This has interesting consequences when we discuss the so-called bias-variance trade-off below. +Hence, \( y_i \sim \mathcal{N}( \mathbf{X}_{i, \ast} \, \boldsymbol{\beta}, \sigma^2) \), that is \( \boldsymbol{y} \) follows a normal distribution with +mean value \( \boldsymbol{X}\boldsymbol{\beta} \) and variance \( \sigma^2 \) (not be confused with the singular values of the SVD).

    @@ -488,7 +441,7 @@ This means the variance we obtain with the standard OLS will always for \( \lamb

  • 41
  • 42
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs033.html b/doc/pub/week36/html/._week36-bs033.html index 0b8245a15..fd01ee389 100644 --- a/doc/pub/week36/html/._week36-bs033.html +++ b/doc/pub/week36/html/._week36-bs033.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,27 +383,87 @@ MathJax.Hub.Config({ -

    Deriving OLS from a probability distribution

    +

    Expectation value and variance for \( \boldsymbol{\beta} \)

    -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 \). +With the OLS expressions for the parameters \( \boldsymbol{\beta} \) we can evaluate the expectation value +$$ +\mathbb{E}(\boldsymbol{\beta}) = \mathbb{E}[ (\mathbf{X}^{\top} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbb{E}[ \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1} \mathbf{X}^{T}\mathbf{X}\boldsymbol{\beta}=\boldsymbol{\beta}. +$$ + +This means that the estimator of the regression parameters is unbiased.

    -We 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 +We can also calculate the variance + +

    +The variance of \( \boldsymbol{\beta} \) is +$$ +\begin{eqnarray*} +\mbox{Var}(\boldsymbol{\beta}) & = & \mathbb{E} \{ [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})] [\boldsymbol{\beta} - \mathbb{E}(\boldsymbol{\beta})]^{T} \} +\\ +& = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \boldsymbol{\beta}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \boldsymbol{\beta}]^{T} \} +\\ +% & = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}]^{T} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} +% \\ +% & = & \mathbb{E} \{ (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} \, \mathbf{Y}^{T} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} \} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} +% \\ +& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \mathbb{E} \{ \mathbf{Y} \, \mathbf{Y}^{T} \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} +\\ +& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \{ \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} \, \mathbf{X}^{T} + \sigma^2 \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} +% \\ +% & = & (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^T \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T % \mathbf{X})^{-1} +% \\ +% & & + \, \, \sigma^2 \, (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T \mathbf{X})^{-1} - \boldsymbol{\beta} \boldsymbol{\beta}^T +\\ +& = & \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} + \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} +\, \, \, = \, \, \, \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1}, +\end{eqnarray*} +$$ + +

    +where we have used that \( \mathbb{E} (\mathbf{Y} \mathbf{Y}^{T}) = +\mathbf{X} \, \boldsymbol{\beta} \, \boldsymbol{\beta}^{T} \, \mathbf{X}^{T} + +\sigma^2 \, \mathbf{I}_{nn} \). From \( \mbox{Var}(\boldsymbol{\beta}) = \sigma^2 +\, (\mathbf{X}^{T} \mathbf{X})^{-1} \), one obtains an estimate of the +variance of the estimate of the \( j \)-th regression coefficient: +\( \boldsymbol{\sigma}^2 (\boldsymbol{\beta}_j ) = \boldsymbol{\sigma}^2 [(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} \). This may be used to +construct a confidence interval for the estimates. + +

    +In a similar way, we can obtain analytical expressions for say the +expectation values of the parameters \( \boldsymbol{\beta} \) and their variance +when we employ Ridge regression, allowing us again to define a confidence interval. + +

    +It is rather straightforward to show that +$$ +\mathbb{E} \big[ \boldsymbol{\beta}^{\mathrm{Ridge}} \big]=(\mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I}_{pp})^{-1} (\mathbf{X}^{\top} \mathbf{X})\boldsymbol{\beta}^{\mathrm{OLS}}. +$$ + +We see clearly that +\( \mathbb{E} \big[ \boldsymbol{\beta}^{\mathrm{Ridge}} \big] \not= \boldsymbol{\beta}^{\mathrm{OLS}} \) for any \( \lambda > 0 \). We say then that the ridge estimator is biased. + +

    +We can also compute the variance as $$ -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]}. +\mbox{Var}[\boldsymbol{\beta}^{\mathrm{Ridge}}]=\sigma^2[ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1} \mathbf{X}^{T} \mathbf{X} \{ [ \mathbf{X}^{\top} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}, $$ +and it is easy to see that if the parameter \( \lambda \) goes to infinity then the variance of Ridge parameters \( \boldsymbol{\beta} \) goes to zero. + +

    +With this, we can compute the difference + +$$ +\mbox{Var}[\boldsymbol{\beta}^{\mathrm{OLS}}]-\mbox{Var}(\boldsymbol{\beta}^{\mathrm{Ridge}})=\sigma^2 [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}[ 2\lambda\mathbf{I} + \lambda^2 (\mathbf{X}^{T} \mathbf{X})^{-1} ] \{ [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}. +$$ + +The difference is non-negative definite since each component of the +matrix product is non-negative definite. +This means the variance we obtain with the standard OLS will always for \( \lambda > 0 \) be larger than the variance of \( \boldsymbol{\beta} \) obtained with the Ridge estimator. This has interesting consequences when we discuss the so-called bias-variance trade-off below. +

    @@ -428,7 +490,7 @@ $$

  • 42
  • 43
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs034.html b/doc/pub/week36/html/._week36-bs034.html index dd2b8edf3..f422b73ec 100644 --- a/doc/pub/week36/html/._week36-bs034.html +++ b/doc/pub/week36/html/._week36-bs034.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,40 +383,27 @@ MathJax.Hub.Config({ -

    Independent and Identically Distrubuted (iid)

    +

    Deriving OLS from a probability 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} \). +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 \).

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

    -We will write this in a more compact form reserving \( \boldsymbol{D} \) for the domain of events, including the ouputs (targets) and the inputs. That is -in case we have a simple one-dimensional input and output case -$$ -\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})]. -$$ - -In the more general case the various inputs should be replaced by the possible features represented by the input data set \( \boldsymbol{X} \). -We can now rewrite the above probability as -$$ -p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}. -$$ - -

    -It is a conditional probability (see below) and reads as the likelihood of a domain of events \( \boldsymbol{D} \) given a set of parameters \( \boldsymbol{\beta} \). -

    @@ -441,7 +430,7 @@ It is a conditional probability (see below) and reads as the likelihood of a dom

  • 43
  • 44
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs035.html b/doc/pub/week36/html/._week36-bs035.html index 10f2720e8..10b295f54 100644 --- a/doc/pub/week36/html/._week36-bs035.html +++ b/doc/pub/week36/html/._week36-bs035.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,32 +383,39 @@ MathJax.Hub.Config({ -

    Maximum Likelihood Estimation (MLE)

    +

    Independent and Identically Distrubuted (iid)

    -In statistics, maximum likelihood estimation (MLE) is a method of -estimating the parameters of an assumed probability distribution, -given some observed data. This is achieved by maximizing a likelihood -function so that, under the assumed statistical model, the observed -data is the most probable. +We 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} \).

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

    -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. +We will write this in a more compact form reserving \( \boldsymbol{D} \) for the domain of events, including the ouputs (targets) and the inputs. That is +in case we have a simple one-dimensional input and output case +$$ +\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})]. +$$ + +In the more general case the various inputs should be replaced by the possible features represented by the input data set \( \boldsymbol{X} \). +We can now rewrite the above probability as +$$ +p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}. +$$

    -Note also that maximization/minimization of the logarithm of the PDF -is equivalent to the maximization/minimization of the function itself. +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} \).

    @@ -434,7 +443,7 @@ is equivalent to the maximization/minimization of the function itself.

  • 44
  • 45
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs036.html b/doc/pub/week36/html/._week36-bs036.html index 6de932992..4eff07622 100644 --- a/doc/pub/week36/html/._week36-bs036.html +++ b/doc/pub/week36/html/._week36-bs036.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,34 +383,32 @@ MathJax.Hub.Config({ -

    A new Cost Function

    +

    Maximum Likelihood Estimation (MLE)

    -We could now define a new cost function to minimize, namely the negative logarithm of the above PDF - -$$ -C(\boldsymbol{\beta}=-\log{\prod_{i=0}^{n-1}p(y_i,\boldsymbol{X}\vert\boldsymbol{\beta})}=-\sum_{i=0}^{n-1}\log{p(y_i,\boldsymbol{X}\vert\boldsymbol{\beta})}, -$$ - -which becomes -$$ -C(\boldsymbol{\beta}=\frac{n}{2}\log{2\pi\sigma^2}+\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}. -$$ +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.

    -Taking the derivative of the new cost function with respect to the parameters \( \beta \) we recognize our familiar OLS equation, namely - -$$ -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right) =0, -$$ - -which leads to the well-known OLS equation for the optimal paramters \( \beta \) -$$ -\hat{\boldsymbol{\beta}}^{\mathrm{OLS}}=\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}! -$$ +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.

    -Before we make a similar analysis for Ridge and Lasso regression, we need a short reminder on statistics. +In practice, it is more convenient to maximize the logarithm of the +PDF because it is a monotonically increasing function of the argument. +Alternatively, and this will be our option, we will minimize the +negative of the logarithm since this is a monotonically decreasing +function. + +

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

    @@ -436,7 +436,7 @@ Before we make a similar analysis for Ridge and Lasso regression, we need a shor

  • 45
  • 46
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs037.html b/doc/pub/week36/html/._week36-bs037.html index c77983682..3b69406aa 100644 --- a/doc/pub/week36/html/._week36-bs037.html +++ b/doc/pub/week36/html/._week36-bs037.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,45 +383,34 @@ MathJax.Hub.Config({ -

    More basic Statistics and Bayes' theorem

    +

    A new Cost Function

    -A central theorem in statistics is Bayes' theorem. This theorem plays a similar role as the good old Pythagoras' theorem in geometry. -Bayes' theorem is extremely simple to derive. But to do so we need some basic axioms from statistics. +We could now define a new cost function to minimize, namely the negative logarithm of the above PDF -

    -Assume we have two domains of events \( X=[x_0,x_1,\dots,x_{n-1}] \) and \( Y=[y_0,y_1,\dots,y_{n-1}] \). - -

    -We define also the likelihood for \( X \) and \( Y \) as \( p(X) \) and \( p(Y) \) respectively. -The likelihood of a specific event \( x_i \) (or \( y_i \)) is then written as \( p(X=x_i) \) or just \( p(x_i)=p_i \). - -

    -

    -
    -

    $$ -p(X \cup Y)= p(X)+p(Y)-p(X \cap Y). -$$ -

    -
    - - -

    -

    -
    -

    -$$ -p(X \cup Y)= p(X,Y)= p(X\vert Y)p(Y)=p(Y\vert X)p(X), +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})}, $$ -where we read \( p(X\vert Y) \) as the likelihood of obtaining \( X \) given \( Y \). -

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

    -If we have independent events then \( p(X,Y)=p(X)p(Y) \). +Taking the derivative of the new cost function with respect to the parameters \( \beta \) we recognize our familiar OLS equation, namely + +$$ +\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right) =0, +$$ + +which leads to the well-known OLS equation for the optimal paramters \( \beta \) +$$ +\hat{\boldsymbol{\beta}}^{\mathrm{OLS}}=\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}! +$$ + +

    +Before we make a similar analysis for Ridge and Lasso regression, we need a short reminder on statistics.

    @@ -447,7 +438,7 @@ If we have independent events then \( p(X,Y)=p(X)p(Y) \).

  • 46
  • 47
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs038.html b/doc/pub/week36/html/._week36-bs038.html index 0a701fcea..f4429d86e 100644 --- a/doc/pub/week36/html/._week36-bs038.html +++ b/doc/pub/week36/html/._week36-bs038.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,20 +383,46 @@ MathJax.Hub.Config({ -

    Marginal Probability

    +

    More basic Statistics and Bayes' theorem

    + +

    +A central theorem in statistics is Bayes' theorem. This theorem plays a similar role as the good old Pythagoras' theorem in geometry. +Bayes' theorem is extremely simple to derive. But to do so we need some basic axioms from statistics. + +

    +Assume we have two domains of events \( X=[x_0,x_1,\dots,x_{n-1}] \) and \( Y=[y_0,y_1,\dots,y_{n-1}] \). + +

    +We define also the likelihood for \( X \) and \( Y \) as \( p(X) \) and \( p(Y) \) respectively. +The likelihood of a specific event \( x_i \) (or \( y_i \)) is then written as \( p(X=x_i) \) or just \( p(x_i)=p_i \).

    -The marginal probability is defined in terms of only one of the set of variables \( X,Y \). For a discrete probability we have

    $$ -p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). +p(X \cup Y)= p(X)+p(Y)-p(X \cap Y). $$

    +

    +

    +
    +

    +$$ +p(X \cup Y)= p(X,Y)= p(X\vert Y)p(Y)=p(Y\vert X)p(X), +$$ + +where we read \( p(X\vert Y) \) as the likelihood of obtaining \( X \) given \( Y \). +

    +
    + + +

    +If we have independent events then \( p(X,Y)=p(X)p(Y) \). +

    @@ -421,7 +449,7 @@ $$

  • 47
  • 48
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs039.html b/doc/pub/week36/html/._week36-bs039.html index 211ad7a42..fde4ab14a 100644 --- a/doc/pub/week36/html/._week36-bs039.html +++ b/doc/pub/week36/html/._week36-bs039.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,15 +383,15 @@ MathJax.Hub.Config({ -

    Conditional Probability

    +

    Marginal Probability

    -The conditional probability, if \( p(Y) > 0 \), is +The marginal probability is defined in terms of only one of the set of variables \( X,Y \). For a discrete probability we have

    $$ -p(X\vert Y)= \frac{p(X,Y)}{p(Y)}=\frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}. +p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). $$

    @@ -421,7 +423,7 @@ $$
  • 48
  • 49
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs040.html b/doc/pub/week36/html/._week36-bs040.html index a860725d7..6a8775fe1 100644 --- a/doc/pub/week36/html/._week36-bs040.html +++ b/doc/pub/week36/html/._week36-bs040.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,21 +383,19 @@ MathJax.Hub.Config({ -

    Bayes' Theorem

    +

    Conditional Probability

    -If we combine the conditional probability with the marginal probability and the standard product rule, we have +The conditional probability, if \( p(Y) > 0 \), is +

    +
    +

    $$ -p(X\vert Y)= \frac{p(X,Y)}{p(Y)}, +p(X\vert Y)= \frac{p(X,Y)}{p(Y)}=\frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}. $$ +

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

    @@ -423,7 +423,7 @@ which is Bayes' theorem. It allows us to evaluate the uncertainty in in \( X \)

  • 49
  • 50
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs041.html b/doc/pub/week36/html/._week36-bs041.html index 5a059e0c2..f08616dbc 100644 --- a/doc/pub/week36/html/._week36-bs041.html +++ b/doc/pub/week36/html/._week36-bs041.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,19 +383,21 @@ MathJax.Hub.Config({ -

    Interpretations of Bayes' Theorem

    +

    Bayes' Theorem

    -The quantity \( p(Y\vert X) \) on the right-hand side of the theorem is -evaluated for the observed data \( Y \) and can be viewed as a function of -the parameter space represented by \( X \). This function is not -necesseraly normalized and is normally called the likelihood function. +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)}, +$$ -

    -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. +which we can rewrite as -

    -Let us try to illustrate Bayes' theorem through an example. +$$ +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 \).

    @@ -421,7 +425,7 @@ Let us try to illustrate Bayes' theorem through an example.

  • 50
  • 51
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs042.html b/doc/pub/week36/html/._week36-bs042.html index 846214847..338b9ca57 100644 --- a/doc/pub/week36/html/._week36-bs042.html +++ b/doc/pub/week36/html/._week36-bs042.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,29 +383,19 @@ MathJax.Hub.Config({ -

    Example of Usage of Bayes' theorem

    +

    Interpretations of Bayes' Theorem

    -Let us suppose that you are undergoing a series of mammography scans in -order to rule out possible breast cancer cases. We define the -sensitivity for a positive event by the variable \( X \). It takes binary -values with \( X=1 \) representing a positive event and \( X=0 \) being a -negative event. We reserve \( Y \) as a classification parameter for -either a negative or a positive breast cancer confirmation. (Short note on wordings: positive here means having breast cancer, although none of us would consider this being a positive thing). +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.

    -We let \( Y=1 \) represent the the case of having breast cancer and \( Y=0 \) as not. +The function \( p(X) \) on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution.

    -Let us assume that if you have breast cancer, the test will be positive with a probability of \( 0.8 \), that is we have - -$$ -p(X=1\vert Y=1) =0.8. -$$ - -

    -This obviously sounds scary since many would conclude that if the test is positive, there is a likelihood of \( 80\% \) for having cancer. -It is however not correct, as the following Bayesian analysis shows. +Let us try to illustrate Bayes' theorem through an example.

    @@ -431,7 +423,7 @@ It is however not correct, as the following Bayesian analysis shows.

  • 51
  • 52
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs043.html b/doc/pub/week36/html/._week36-bs043.html index 0d7f06734..339def1cc 100644 --- a/doc/pub/week36/html/._week36-bs043.html +++ b/doc/pub/week36/html/._week36-bs043.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,30 +383,29 @@ MathJax.Hub.Config({ -

    Doing it correctly

    +

    Example of Usage of Bayes' theorem

    -If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. -Let us assume that the prior probability in the population as a whole is +Let us suppose that you are undergoing a series of mammography scans in +order to rule out possible breast cancer cases. We define the +sensitivity for a positive event by the variable \( X \). It takes binary +values with \( X=1 \) representing a positive event and \( X=0 \) being a +negative event. We reserve \( Y \) as a classification parameter for +either a negative or a positive breast cancer confirmation. (Short note on wordings: positive here means having breast cancer, although none of us would consider this being a positive thing). + +

    +We let \( Y=1 \) represent the the case of having breast cancer and \( Y=0 \) as not. + +

    +Let us assume that if you have breast cancer, the test will be positive with a probability of \( 0.8 \), that is we have $$ -p(Y=1) =0.004. +p(X=1\vert Y=1) =0.8. $$

    -We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have -$$ -p(X=1\vert Y=0) =0.1. -$$ - -

    -Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute - -$$ -p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. -$$ - -That is, in case of a positive test, there is only a \( 3\% \) chance of having breast cancer! +This obviously sounds scary since many would conclude that if the test is positive, there is a likelihood of \( 80\% \) for having cancer. +It is however not correct, as the following Bayesian analysis shows.

    @@ -432,7 +433,7 @@ That is, in case of a positive test, there is only a \( 3\% \) chance of having

  • 52
  • 53
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs044.html b/doc/pub/week36/html/._week36-bs044.html index 61595c542..913b1d866 100644 --- a/doc/pub/week36/html/._week36-bs044.html +++ b/doc/pub/week36/html/._week36-bs044.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,16 +383,30 @@ MathJax.Hub.Config({ -

    Bayes' Theorem and Ridge and Lasso Regression

    +

    Doing it correctly

    -Hitherto we have discussed Ridge and Lasso regression in terms of a -linear analysis. This may to many of you feel rather technical and -perhaps not that intuitive. The question is whether we can develop a -more intuitive way of understanding what Ridge and Lasso express. +If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. +Let us assume that the prior probability in the population as a whole is + +$$ +p(Y=1) =0.004. +$$

    -Before we proceed let us perform a Ridge, Lasso and OLS analysis of a polynomial fit. +We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have +$$ +p(X=1\vert Y=0) =0.1. +$$ + +

    +Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute + +$$ +p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. +$$ + +That is, in case of a positive test, there is only a \( 3\% \) chance of having breast cancer!

    @@ -418,7 +434,7 @@ Before we proceed let us perform a Ridge, Lasso and OLS analysis of a polynomia

  • 53
  • 54
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs045.html b/doc/pub/week36/html/._week36-bs045.html index 869df30c0..81c7cc49d 100644 --- a/doc/pub/week36/html/._week36-bs045.html +++ b/doc/pub/week36/html/._week36-bs045.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,87 +383,16 @@ MathJax.Hub.Config({ -

    Test Function for what happens with OLS, Ridge and Lasso

    +

    Bayes' Theorem and Ridge and Lasso Regression

    -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. +Hitherto we have discussed Ridge and Lasso regression in terms of a +linear analysis. This may to many of you feel rather technical and +perhaps not that intuitive. The question is whether we can develop a +more intuitive way of understanding what Ridge and Lasso express.

    -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 matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    -
    -def R2(y_data, y_model):
    -    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    -def MSE(y_data,y_model):
    -    n = np.size(y_model)
    -    return np.sum((y_data-y_model)**2)/n
    -
    -# Make data set.
    -n = 10000
    -x = np.random.rand(n)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    -
    -Maxpolydegree = 5
    -X = np.zeros((len(x),Maxpolydegree))
    -X[:,0] = 1.0
    -
    -for polydegree in range(1, Maxpolydegree):
    -    for degree in range(polydegree):
    -        X[:,degree] = x**(degree)
    -
    -
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# matrix inversion to find beta
    -OLSbeta = np.linalg.pinv(X_train.T @ X_train) @ X_train.T @ y_train
    -print(OLSbeta)
    -ypredictOLS = X_test @ OLSbeta
    -print("Test MSE OLS")
    -print(MSE(y_test,ypredictOLS))
    -# Repeat now for Lasso and Ridge regression and various values of the regularization parameter using Scikit-Learn
    -# Decide which values of lambda to use
    -nlambdas = 4
    -MSERidgePredict = np.zeros(nlambdas)
    -MSELassoPredict = np.zeros(nlambdas)
    -lambdas = np.logspace(-3, 1, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    # Make the fit using Ridge and Lasso
    -    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    -    RegRidge.fit(X_train,y_train)
    -    RegLasso = linear_model.Lasso(lmb,fit_intercept=False)
    -    RegLasso.fit(X_train,y_train)
    -    # and then make the prediction
    -    ypredictRidge = RegRidge.predict(X_test)
    -    ypredictLasso = RegLasso.predict(X_test)
    -    # Compute the MSE and print it
    -    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    -    MSELassoPredict[i] = MSE(y_test,ypredictLasso)
    -    print(lmb,RegRidge.coef_)
    -    print(lmb,RegLasso.coef_)
    -# Now plot the results
    -plt.figure()
    -plt.plot(np.log10(lambdas), MSERidgePredict, 'b', label = 'MSE Ridge Test')
    -plt.plot(np.log10(lambdas), MSELassoPredict, 'r', label = 'MSE Lasso Test')
    -plt.xlabel('log10(lambda)')
    -plt.ylabel('MSE')
    -plt.legend()
    -plt.show()
    -
    -

    -How can we understand this? +Before we proceed let us perform a Ridge, Lasso and OLS analysis of a polynomial fit.

    @@ -489,7 +420,7 @@ How can we understand this?

  • 54
  • 55
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs046.html b/doc/pub/week36/html/._week36-bs046.html index 64a43cd8d..3023108e7 100644 --- a/doc/pub/week36/html/._week36-bs046.html +++ b/doc/pub/week36/html/._week36-bs046.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,37 +383,87 @@ MathJax.Hub.Config({ -

    Invoking Bayes' theorem

    +

    Test Function for what happens with OLS, Ridge and Lasso

    -Using Bayes' theorem we can gain a better intuition about Ridge and Lasso regression. +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 ordinary least squares we postulated that the maximum likelihood for the doamin of events \( \boldsymbol{D} \) (one-dimensional case) -$$ -\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})], -$$ - -is given by -$$ -p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}. -$$ +For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one.

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

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
     
    +def R2(y_data, y_model):
    +    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    +def MSE(y_data,y_model):
    +    n = np.size(y_model)
    +    return np.sum((y_data-y_model)**2)/n
    +
    +# Make data set.
    +n = 10000
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((len(x),Maxpolydegree))
    +X[:,0] = 1.0
    +
    +for polydegree in range(1, Maxpolydegree):
    +    for degree in range(polydegree):
    +        X[:,degree] = x**(degree)
    +
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# matrix inversion to find beta
    +OLSbeta = np.linalg.pinv(X_train.T @ X_train) @ X_train.T @ y_train
    +print(OLSbeta)
    +ypredictOLS = X_test @ OLSbeta
    +print("Test MSE OLS")
    +print(MSE(y_test,ypredictOLS))
    +# Repeat now for Lasso and Ridge regression and various values of the regularization parameter using Scikit-Learn
    +# Decide which values of lambda to use
    +nlambdas = 4
    +MSERidgePredict = np.zeros(nlambdas)
    +MSELassoPredict = np.zeros(nlambdas)
    +lambdas = np.logspace(-3, 1, nlambdas)
    +for i in range(nlambdas):
    +    lmb = lambdas[i]
    +    # Make the fit using Ridge and Lasso
    +    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    +    RegRidge.fit(X_train,y_train)
    +    RegLasso = linear_model.Lasso(lmb,fit_intercept=False)
    +    RegLasso.fit(X_train,y_train)
    +    # and then make the prediction
    +    ypredictRidge = RegRidge.predict(X_test)
    +    ypredictLasso = RegLasso.predict(X_test)
    +    # Compute the MSE and print it
    +    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    +    MSELassoPredict[i] = MSE(y_test,ypredictLasso)
    +    print(lmb,RegRidge.coef_)
    +    print(lmb,RegLasso.coef_)
    +# Now plot the results
    +plt.figure()
    +plt.plot(np.log10(lambdas), MSERidgePredict, 'b', label = 'MSE Ridge Test')
    +plt.plot(np.log10(lambdas), MSELassoPredict, 'r', label = 'MSE Lasso Test')
    +plt.xlabel('log10(lambda)')
    +plt.ylabel('MSE')
    +plt.legend()
    +plt.show()
    +

    -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} \)! +How can we understand this?

    @@ -439,7 +491,7 @@ We have a model for \( p(\boldsymbol{D}\vert\boldsymbol{\beta}) \) but need one

  • 55
  • 56
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs047.html b/doc/pub/week36/html/._week36-bs047.html index 32782bdbe..44d803ec5 100644 --- a/doc/pub/week36/html/._week36-bs047.html +++ b/doc/pub/week36/html/._week36-bs047.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,43 +383,37 @@ MathJax.Hub.Config({ -

    Ridge and Bayes

    +

    Invoking Bayes' theorem

    -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. +Using Bayes' theorem we can gain a better intuition about Ridge and Lasso regression.

    -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 - +For ordinary least squares we postulated that the maximum likelihood for the doamin of events \( \boldsymbol{D} \) (one-dimensional case) $$ -p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\beta_j^2}{2\tau^2}\right)}. +\boldsymbol{D}=[(x_0,y_0), (x_1,y_1),\dots, (x_{n-1},y_{n-1})], +$$ + +is given by +$$ +p(\boldsymbol{D}\vert\boldsymbol{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}. $$

    -Our posterior probability becomes then (omitting the normalization factor which is just a constant) +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})}=\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)}. +p(\boldsymbol{\beta}\vert\boldsymbol{D}). $$

    -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 - +Bayes' theorem comes to our rescue here since (omitting the normalization constant) $$ -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, +p(\boldsymbol{\beta}\vert\boldsymbol{D})\propto p(\boldsymbol{D}\vert\boldsymbol{\beta})p(\boldsymbol{\beta}). $$ -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? +

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

    @@ -445,7 +441,7 @@ which is our Ridge cost function! Nice, isn't it?

  • 56
  • 57
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs048.html b/doc/pub/week36/html/._week36-bs048.html index 764f0fe91..0c31bc51e 100644 --- a/doc/pub/week36/html/._week36-bs048.html +++ b/doc/pub/week36/html/._week36-bs048.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,37 +383,43 @@ MathJax.Hub.Config({ -

    Lasso and Bayes

    +

    Ridge 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 +With the posterior probability defined by a likelihood which we have +already modeled and an unknown prior, we are now ready to make +additional models for the prior. + +

    +We can, based on our discussions of the variance of \( \boldsymbol{\beta} \) and the mean value, assume that the prior for the values \( \boldsymbol{\beta} \) is given by a Gaussian with mean value zero and variance \( \tau^2 \), that is $$ -p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}. +p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\beta_j^2}{2\tau^2}\right)}. $$

    Our posterior probability becomes then (omitting the normalization factor which is just a constant) $$ -p(\boldsymbol{\beta}\vert\boldsymbol{D})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}. +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)}. $$

    -Taking the negative -logarithm of the posterior probability and leaving out the +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}{\tau}\vert\vert\boldsymbol{\beta}\vert\vert_1, +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/\tau \) 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_1, +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 Lasso cost function! +which is our Ridge cost function! Nice, isn't it?

    @@ -439,7 +447,7 @@ which is our Lasso cost function!

  • 57
  • 58
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs049.html b/doc/pub/week36/html/._week36-bs049.html index 1d1222f6f..3c1fe96b5 100644 --- a/doc/pub/week36/html/._week36-bs049.html +++ b/doc/pub/week36/html/._week36-bs049.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,19 +383,37 @@ MathJax.Hub.Config({ -

    Why resampling methods

    +

    Lasso and Bayes

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

      -
    1. look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff
    2. -
    3. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more
    4. -
    +$$ +p(\boldsymbol{\beta})=\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}. +$$ -This will allow us to link the standard linear algebra methods we have discussed above to a statistical interpretation of the methods. +

    +Our posterior probability becomes then (omitting the normalization factor which is just a constant) +$$ +p(\boldsymbol{\beta}\vert\boldsymbol{D})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\boldsymbol{X}_{i,*}\boldsymbol{\beta})^2}{2\sigma^2}\right]}\prod_{j=0}^{p-1}\exp{\left(-\frac{\vert\beta_j\vert}{\tau}\right)}. +$$ + +

    +Taking the negative +logarithm of the posterior probability and leaving out the +constants terms that do not depend on \( \beta \), we have + +$$ +C(\boldsymbol{\beta}=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\frac{1}{\tau}\vert\vert\boldsymbol{\beta}\vert\vert_1, +$$ + +and replacing \( 1/\tau \) with \( \lambda \) we have + +$$ +C(\boldsymbol{\beta}=\frac{\vert\vert (\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\vert\vert_2^2}{2\sigma^2}+\lambda\vert\vert\boldsymbol{\beta}\vert\vert_1, +$$ + +which is our Lasso cost function!

    @@ -421,7 +441,7 @@ This will allow us to link the standard linear algebra methods we have discussed

  • 58
  • 59
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs050.html b/doc/pub/week36/html/._week36-bs050.html index a3b53a757..ba67a036e 100644 --- a/doc/pub/week36/html/._week36-bs050.html +++ b/doc/pub/week36/html/._week36-bs050.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,36 +383,19 @@ MathJax.Hub.Config({ -

    Resampling methods

    -
    -
    -

    -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 -order to estimate the variability of a linear regression fit, we can -repeatedly draw different samples from the training data, fit a linear -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. +

    Why resampling methods

    -Two resampling methods are often used in Machine Learning analyses, +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. The bootstrap method
    2. -
    3. and Cross-Validation
    4. +
    5. look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff
    6. +
    7. introduce resampling techniques like cross-validation, bootstrapping and jackknife and more
    -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. - -

    -

    -
    - +This will allow us to link the standard linear algebra methods we have discussed above to a statistical interpretation of the methods.

    @@ -438,7 +423,7 @@ cross-validation and the bootstrap method.

  • 59
  • 60
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs051.html b/doc/pub/week36/html/._week36-bs051.html index 969840f2b..98de91257 100644 --- a/doc/pub/week36/html/._week36-bs051.html +++ b/doc/pub/week36/html/._week36-bs051.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,27 +383,31 @@ MathJax.Hub.Config({ -

    Resampling approaches can be computationally expensive

    +

    Resampling methods

    +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 +order to estimate the variability of a linear regression fit, we can +repeatedly draw different samples from the training data, fit a linear +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.

    -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 -resampling methods generally are not prohibitive. In this chapter, we -discuss two of the most commonly used resampling methods, -cross-validation and the bootstrap. Both methods are important tools -in the practical application of many statistical learning -procedures. For example, cross-validation can be used to estimate the -test error associated with a given statistical learning method in -order to evaluate its performance, or to select the appropriate level -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. +Two resampling methods are often used in Machine Learning analyses, + +

      +
    1. The bootstrap method
    2. +
    3. and Cross-Validation
    4. +
    + +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.

    @@ -434,7 +440,7 @@ bootstrap is widely used.
  • 60
  • 61
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs052.html b/doc/pub/week36/html/._week36-bs052.html index 330ee3d0b..c4963a974 100644 --- a/doc/pub/week36/html/._week36-bs052.html +++ b/doc/pub/week36/html/._week36-bs052.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,16 +383,29 @@ MathJax.Hub.Config({ -

    Why resampling methods ?

    +

    Resampling approaches can be computationally expensive

    -

      -
    • Our simulations can be treated as computer experiments. This is particularly the case for Monte Carlo methods
    • -
    • The results can be analysed with the same statistical tools as we would use analysing experimental data.
    • -
    • As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.
    • -
    +

    +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 +resampling methods generally are not prohibitive. In this chapter, we +discuss two of the most commonly used resampling methods, +cross-validation and the bootstrap. Both methods are important tools +in the practical application of many statistical learning +procedures. For example, cross-validation can be used to estimate the +test error associated with a given statistical learning method in +order to evaluate its performance, or to select the appropriate level +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. + +

    @@ -421,7 +436,7 @@ MathJax.Hub.Config({
  • 61
  • 62
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs053.html b/doc/pub/week36/html/._week36-bs053.html index 786f3898d..ae73edc4f 100644 --- a/doc/pub/week36/html/._week36-bs053.html +++ b/doc/pub/week36/html/._week36-bs053.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,21 +383,15 @@ MathJax.Hub.Config({ -

    Statistical analysis

    +

    Why resampling methods ?

      -
    • 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.
    • +
    • Our simulations can be treated as computer experiments. This is particularly the case for Monte Carlo methods
    • +
    • The results can be analysed with the same statistical tools as we would use analysing experimental data.
    • +
    • As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.
    @@ -427,7 +423,7 @@ MathJax.Hub.Config({
  • 62
  • 63
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs054.html b/doc/pub/week36/html/._week36-bs054.html index 0270c983b..9374e7848 100644 --- a/doc/pub/week36/html/._week36-bs054.html +++ b/doc/pub/week36/html/._week36-bs054.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,31 +383,25 @@ MathJax.Hub.Config({ -

    Resampling methods

    +

    Statistical analysis

    +
    +
    +

    -

    -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 us to a discussion of the so-called bias-variance tradeoff (see -below) and so-called resampling methods. +

      +
    • As in other experiments, many numerical experiments have two classes of errors:
    • -

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

        +
      • Statistical errors
      • +
      • Systematical errors
      • +
      -

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

    • Statistical errors can be estimated using standard tools from statistics
    • +
    • Systematical errors are method specific and must be treated differently from case to case.
    • +
    +
    +
    -
      -
    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. -
    3. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    4. -
    - -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.

    @@ -433,7 +429,7 @@ training error reaches a saturation.

  • 63
  • 64
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs055.html b/doc/pub/week36/html/._week36-bs055.html index 35296bc5a..f542ed657 100644 --- a/doc/pub/week36/html/._week36-bs055.html +++ b/doc/pub/week36/html/._week36-bs055.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,25 +383,31 @@ MathJax.Hub.Config({ -

    Resampling methods: Jackknife and Bootstrap

    +

    Resampling methods

    -Two famous -resampling methods are the independent bootstrap and the jackknife. +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 us to a discussion of the so-called bias-variance tradeoff (see +below) and so-called resampling methods.

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

    -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. +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. +
    3. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    4. +
    + +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.

    @@ -427,7 +435,7 @@ need for bootstrapping.

  • 64
  • 65
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs056.html b/doc/pub/week36/html/._week36-bs056.html index 1086dcbdf..8e75639a6 100644 --- a/doc/pub/week36/html/._week36-bs056.html +++ b/doc/pub/week36/html/._week36-bs056.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,21 +383,25 @@ MathJax.Hub.Config({ -

    Resampling methods: Jackknife

    +

    Resampling methods: Jackknife and Bootstrap

    -The Jackknife works by making many replicas of the estimator \( \widehat{\theta} \). -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), -$$ +Two famous +resampling methods are the independent bootstrap and the jackknife.

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

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

    @@ -423,7 +429,7 @@ number \( i \) is left out. Using this notation, define

  • 65
  • 66
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs057.html b/doc/pub/week36/html/._week36-bs057.html index 94f4b59ba..63fcc4106 100644 --- a/doc/pub/week36/html/._week36-bs057.html +++ b/doc/pub/week36/html/._week36-bs057.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,39 +383,22 @@ MathJax.Hub.Config({ -

    Jackknife code example

    +

    Resampling methods: Jackknife

    +

    +The Jackknife works by making many replicas of the estimator \( \widehat{\theta} \). +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), +$$ - -

    from numpy import *
    -from numpy.random import randint, randn
    -from time import time
    +

    +which equals the vector \( \boldsymbol{x} \) with the exception that observation +number \( i \) is left out. Using this notation, define +\( \widehat{\theta}_i \) to be the estimator +\( \widehat{\theta} \) computed using \( \vec{X}_i \). -def jackknife(data, stat): - n = len(data);t = zeros(n); inds = arange(n); t0 = time() - ## 'jackknifing' by leaving out an observation for each i - for i in range(n): - t[i] = stat(delete(data,i) ) - - # 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)) - - return t - - -# Returns mean of data samples -def stat(data): - return mean(data) - - -mu, sigma = 100, 15 -datapoints = 10000 -x = mu + sigma*random.randn(datapoints) -# jackknife returns the data sample -t = jackknife(x, stat) -

    @@ -440,7 +425,7 @@ t = jackknife(x, stat)

  • 66
  • 67
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs058.html b/doc/pub/week36/html/._week36-bs058.html index 0fb2c1ef1..01b8820ab 100644 --- a/doc/pub/week36/html/._week36-bs058.html +++ b/doc/pub/week36/html/._week36-bs058.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,25 +383,39 @@ MathJax.Hub.Config({ -

    Resampling methods: Bootstrap

    -
    -
    -

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

    Jackknife code example

    +

    -

      -
    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. -
    3. 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.
    4. -
    5. It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.
    6. -
    7. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).
    8. -
    -
    -
    + +
    from numpy import *
    +from numpy.random import randint, randn
    +from time import time
    +
    +def jackknife(data, stat):
    +    n = len(data);t = zeros(n); inds = arange(n); t0 = time()
    +    ## 'jackknifing' by leaving out an observation for each i                                                                                                                      
    +    for i in range(n):
    +        t[i] = stat(delete(data,i) )
    +
    +    # 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))
    +
    +    return t
     
     
    +# Returns mean of data samples                                                                                                                                                     
    +def stat(data):
    +    return mean(data)
    +
    +
    +mu, sigma = 100, 15
    +datapoints = 10000
    +x = mu + sigma*random.randn(datapoints)
    +# jackknife returns the data sample                                                                                                                                                
    +t = jackknife(x, stat)
    +

    @@ -426,7 +442,7 @@ advantages:

  • 67
  • 68
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs059.html b/doc/pub/week36/html/._week36-bs059.html index c51a6797e..76149d22c 100644 --- a/doc/pub/week36/html/._week36-bs059.html +++ b/doc/pub/week36/html/._week36-bs059.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,18 +383,24 @@ MathJax.Hub.Config({ -

    Resampling methods: Bootstrap background

    +

    Resampling methods: Bootstrap

    +
    +
    +

    +Bootstrapping is a nonparametric 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. +
    3. 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.
    4. +
    5. It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.
    6. +
    7. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).
    8. +
    +
    +
    -

    -Since \( \widehat{\theta} = \widehat{\theta}(\boldsymbol{X}) \) is a function of random variables, -\( \widehat{\theta} \) 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 -\( \widehat{\theta} \). You can think of this as using a histogram -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.

    @@ -420,7 +428,7 @@ estimators.

  • 68
  • 69
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs060.html b/doc/pub/week36/html/._week36-bs060.html index 3bebbbb4c..9a33b1483 100644 --- a/doc/pub/week36/html/._week36-bs060.html +++ b/doc/pub/week36/html/._week36-bs060.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,24 +383,18 @@ MathJax.Hub.Config({ -

    Resampling methods: More Bootstrap background

    +

    Resampling methods: Bootstrap background

    -In the case that \( \widehat{\theta} \) 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 straight forward 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. -
    3. Then using these numbers, we could compute a replica of \( \widehat{\theta} \) called \( \widehat{\theta}^* \).
    4. -
    - -By repeated use of (1) and (2), many -estimates of \( \widehat{\theta} \) could have been obtained. The -idea is to use the relative frequency of \( \widehat{\theta}^* \) -(think of a histogram) as an estimate of \( p(\boldsymbol{t}) \). +Since \( \widehat{\theta} = \widehat{\theta}(\boldsymbol{X}) \) is a function of random variables, +\( \widehat{\theta} \) 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 +\( \widehat{\theta} \). You can think of this as using a histogram +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.

    @@ -426,7 +422,7 @@ idea is to use the relative frequency of \( \widehat{\theta}^* \)

  • 69
  • 70
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs061.html b/doc/pub/week36/html/._week36-bs061.html index 894ef3456..f49afd9a7 100644 --- a/doc/pub/week36/html/._week36-bs061.html +++ b/doc/pub/week36/html/._week36-bs061.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,23 +383,24 @@ MathJax.Hub.Config({ -

    Resampling methods: Bootstrap approach

    +

    Resampling methods: More Bootstrap background

    -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 -the relative frequency of the observations, will we obtain the same -result in some asymptotic sense? The answer is yes. +In the case that \( \widehat{\theta} \) 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 straight forward to do this by: -

    -Instead of generating the histogram for the relative -frequency of the observation \( X_i \), just draw the values -\( (X_1^*,X_2^*,\cdots,X_n^*) \) with replacement from the vector -\( \boldsymbol{X} \). +

      +
    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. +
    3. Then using these numbers, we could compute a replica of \( \widehat{\theta} \) called \( \widehat{\theta}^* \).
    4. +
    + +By repeated use of (1) and (2), many +estimates of \( \widehat{\theta} \) could have been obtained. The +idea is to use the relative frequency of \( \widehat{\theta}^* \) +(think of a histogram) as an estimate of \( p(\boldsymbol{t}) \).

    @@ -425,7 +428,7 @@ frequency of the observation \( X_i \), just draw the values

  • 70
  • 71
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs062.html b/doc/pub/week36/html/._week36-bs062.html index a84ecddc2..e7f044edc 100644 --- a/doc/pub/week36/html/._week36-bs062.html +++ b/doc/pub/week36/html/._week36-bs062.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,27 +383,23 @@ MathJax.Hub.Config({ -

    Resampling methods: Bootstrap steps

    +

    Resampling methods: Bootstrap approach

    -The independent bootstrap works like this: +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 +the relative frequency of the observations, will we obtain the same +result in some asymptotic sense? The answer is yes. -

      -
    1. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    2. -
    3. Define a vector \( \boldsymbol{x}^* \) containing the values which were drawn from \( \boldsymbol{x} \).
    4. -
    5. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\theta}^* \) by evaluating \( \widehat \theta \) under the observations \( \boldsymbol{x}^* \).
    6. -
    7. Repeat this process \( k \) times.
    8. -
    - -When you are done, you can draw a histogram of the relative frequency -of \( \widehat \theta^* \). 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 -histogram of the relative frequency of \( \widehat{\theta}^* \). Instead -you use the estimators corresponding to the statistic of interest. For -example, if you are interested in estimating the variance of \( \widehat -\theta \), apply the etsimator \( \widehat \sigma^2 \) to the values -\( \widehat \theta ^* \). +

    +Instead of generating the histogram for the relative +frequency of the observation \( X_i \), just draw the values +\( (X_1^*,X_2^*,\cdots,X_n^*) \) with replacement from the vector +\( \boldsymbol{X} \).

    @@ -429,7 +427,7 @@ example, if you are interested in estimating the variance of \( \widehat

  • 71
  • 72
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs063.html b/doc/pub/week36/html/._week36-bs063.html index 18d690f39..90ef4808b 100644 --- a/doc/pub/week36/html/._week36-bs063.html +++ b/doc/pub/week36/html/._week36-bs063.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,67 +383,28 @@ MathJax.Hub.Config({ -

    Code example for the Bootstrap method

    +

    Resampling methods: Bootstrap steps

    -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 -data points). This data set consists of estimated mean values for each -bootstrap operation. The histogram generated by the bootstrap method -shows that the distribution for these mean values is also a Gaussian, -centered around the mean value \( \mu=100 \) but with standard deviation -\( \sigma/\sqrt{n} \), where \( n \) is the number of bootstrap samples (in -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. +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. +
    3. Define a vector \( \boldsymbol{x}^* \) containing the values which were drawn from \( \boldsymbol{x} \).
    4. +
    5. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\theta}^* \) by evaluating \( \widehat \theta \) under the observations \( \boldsymbol{x}^* \).
    6. +
    7. Repeat this process \( k \) times.
    8. +
    - -
    from numpy import *
    -from numpy.random import randint, randn
    -from time import time
    -import matplotlib.mlab as mlab
    -import matplotlib.pyplot as plt
    +When you are done, you can draw a histogram of the relative frequency
    +of \( \widehat \theta^* \). 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
    +histogram of the relative frequency of \( \widehat{\theta}^* \). Instead
    +you use the estimators corresponding to the statistic of interest. For
    +example, if you are interested in estimating the variance of \( \widehat
    +\theta \), apply the etsimator \( \widehat \sigma^2 \) to the values
    +\( \widehat \theta ^* \).
     
    -# Returns mean of bootstrap samples                                                                                                                                                
    -def stat(data):
    -    return mean(data)
    -
    -# Bootstrap algorithm
    -def bootstrap(data, statistic, R):
    -    t = zeros(R); n = len(data); inds = arange(n); t0 = time()
    -    # non-parametric bootstrap         
    -    for i in range(R):
    -        t[i] = statistic(data[randint(0,n,n)])
    -
    -    # analysis    
    -    print("Runtime: %g sec" % (time()-t0)); print("Bootstrap Statistics :")
    -    print("original           bias      std. error")
    -    print("%8g %8g %14g %15g" % (statistic(data), std(data),mean(t),std(t)))
    -    return t
    -
    -
    -mu, sigma = 100, 15
    -datapoints = 10000
    -x = mu + sigma*random.randn(datapoints)
    -# bootstrap returns the data sample                                    
    -t = bootstrap(x, stat, datapoints)
    -# the histogram of the bootstrapped  data                                                                                                    
    -n, binsboot, patches = plt.hist(t, 50, normed=1, facecolor='red', alpha=0.75)
    -
    -# add a 'best fit' line  
    -y = mlab.normpdf( binsboot, mean(t), std(t))
    -lt = plt.plot(binsboot, y, 'r--', linewidth=1)
    -plt.xlabel('Smarts')
    -plt.ylabel('Probability')
    -plt.axis([99.5, 100.6, 0, 3.0])
    -plt.grid(True)
    -
    -plt.show()
    -

    @@ -468,7 +431,7 @@ plt.show()

  • 72
  • 73
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs064.html b/doc/pub/week36/html/._week36-bs064.html index 466ede96d..ce4b5f939 100644 --- a/doc/pub/week36/html/._week36-bs064.html +++ b/doc/pub/week36/html/._week36-bs064.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,26 +381,69 @@ MathJax.Hub.Config({

     

     

     

    - + -

    Various steps in cross-validation

    +

    Code example for the Bootstrap method

    -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 -this \( k \)-fold cross-validation structures the data splitting. The -samples are divided into \( k \) more or less equally sized exhaustive and -mutually exclusive subsets. In turn (at each split) one of these -subsets plays the role of the test set while the union of the -remaining subsets constitutes the training set. Such a splitting -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). +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 +data points). This data set consists of estimated mean values for each +bootstrap operation. The histogram generated by the bootstrap method +shows that the distribution for these mean values is also a Gaussian, +centered around the mean value \( \mu=100 \) but with standard deviation +\( \sigma/\sqrt{n} \), where \( n \) is the number of bootstrap samples (in +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. +

    + + +

    from numpy import *
    +from numpy.random import randint, randn
    +from time import time
    +import matplotlib.mlab as mlab
    +import matplotlib.pyplot as plt
    +
    +# Returns mean of bootstrap samples                                                                                                                                                
    +def stat(data):
    +    return mean(data)
    +
    +# Bootstrap algorithm
    +def bootstrap(data, statistic, R):
    +    t = zeros(R); n = len(data); inds = arange(n); t0 = time()
    +    # non-parametric bootstrap         
    +    for i in range(R):
    +        t[i] = statistic(data[randint(0,n,n)])
    +
    +    # analysis    
    +    print("Runtime: %g sec" % (time()-t0)); print("Bootstrap Statistics :")
    +    print("original           bias      std. error")
    +    print("%8g %8g %14g %15g" % (statistic(data), std(data),mean(t),std(t)))
    +    return t
    +
    +
    +mu, sigma = 100, 15
    +datapoints = 10000
    +x = mu + sigma*random.randn(datapoints)
    +# bootstrap returns the data sample                                    
    +t = bootstrap(x, stat, datapoints)
    +# the histogram of the bootstrapped  data                                                                                                    
    +n, binsboot, patches = plt.hist(t, 50, normed=1, facecolor='red', alpha=0.75)
    +
    +# add a 'best fit' line  
    +y = mlab.normpdf( binsboot, mean(t), std(t))
    +lt = plt.plot(binsboot, y, 'r--', linewidth=1)
    +plt.xlabel('Smarts')
    +plt.ylabel('Probability')
    +plt.axis([99.5, 100.6, 0, 3.0])
    +plt.grid(True)
    +
    +plt.show()
    +

    @@ -425,7 +470,7 @@ cross-validation (LOOCV).

  • 73
  • 74
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs065.html b/doc/pub/week36/html/._week36-bs065.html index d4060d61c..61d23694e 100644 --- a/doc/pub/week36/html/._week36-bs065.html +++ b/doc/pub/week36/html/._week36-bs065.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,34 +383,23 @@ MathJax.Hub.Config({ -

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

    +

    Various steps in cross-validation

    - - -$$ -\begin{align*} -\boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T} -\boldsymbol{X}_{-i, \ast} + \lambda \boldsymbol{I}_{pp})^{-1} -\boldsymbol{X}_{-i, \ast}^{T} \boldsymbol{y}_{-i} -\end{align*} -$$ - - - - -$$ -\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*} -$$ +

    +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 +this \( k \)-fold cross-validation structures the data splitting. The +samples are divided into \( k \) more or less equally sized exhaustive and +mutually exclusive subsets. In turn (at each split) one of these +subsets plays the role of the test set while the union of the +remaining subsets constitutes the training set. Such a splitting +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).

    @@ -436,7 +427,7 @@ $$

  • 74
  • 75
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs066.html b/doc/pub/week36/html/._week36-bs066.html index 56c85ffe2..9fc7fab55 100644 --- a/doc/pub/week36/html/._week36-bs066.html +++ b/doc/pub/week36/html/._week36-bs066.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,28 +381,38 @@ MathJax.Hub.Config({

     

     

     

    - + -

    Cross-validation in brief

    +

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

    + + + +$$ +\begin{align*} +\boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T} +\boldsymbol{X}_{-i, \ast} + \lambda \boldsymbol{I}_{pp})^{-1} +\boldsymbol{X}_{-i, \ast}^{T} \boldsymbol{y}_{-i} +\end{align*} +$$ + + + + +$$ +\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*} +$$

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

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

    diff --git a/doc/pub/week36/html/._week36-bs067.html b/doc/pub/week36/html/._week36-bs067.html index e5a0641c8..b400d8e82 100644 --- a/doc/pub/week36/html/._week36-bs067.html +++ b/doc/pub/week36/html/._week36-bs067.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,104 +383,26 @@ MathJax.Hub.Config({ -

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

    +

    Cross-validation in brief

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

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

    import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import KFold
    -from sklearn.linear_model import Ridge
    -from sklearn.model_selection import cross_val_score
    -from sklearn.preprocessing import PolynomialFeatures
    +
      +
    1. shuffle the dataset randomly.
    2. +
    3. Split the dataset into \( k \) groups.
    4. +
    5. For each unique group: -# A seed just to ensure that the random numbers are the same for every run. -# Useful for eventual debugging. -np.random.seed(3155) +
        +
      1. Decide which group to use as set for test data
      2. +
      3. Take the remaining groups as a training data set
      4. +
      5. Fit a model on the training set and evaluate it on the test set
      6. +
      7. Retain the evaluation score and discard the model
      8. +
      -# Generate the data. -nsamples = 100 -x = np.random.randn(nsamples) -y = 3*x**2 + np.random.randn(nsamples) +
    6. Summarize the model using the sample of model evaluation scores
    7. +
    -## Cross-validation on Ridge regression using KFold only - -# Decide degree on polynomial to fit -poly = PolynomialFeatures(degree = 6) - -# Decide which values of lambda to use -nlambdas = 500 -lambdas = np.logspace(-3, 5, nlambdas) - -# Initialize a KFold instance -k = 5 -kfold = KFold(n_splits = k) - -# Perform the cross-validation to estimate MSE -scores_KFold = np.zeros((nlambdas, k)) - -i = 0 -for lmb in lambdas: - ridge = Ridge(alpha = lmb) - 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]) - ridge.fit(Xtrain, ytrain[:, np.newaxis]) - - Xtest = poly.fit_transform(xtest[:, np.newaxis]) - ypred = ridge.predict(Xtest) - - scores_KFold[i,j] = np.sum((ypred - ytest[:, np.newaxis])**2)/np.size(ypred) - - j += 1 - i += 1 - - -estimated_mse_KFold = np.mean(scores_KFold, axis = 1) - -## Cross-validation using cross_val_score from sklearn along with KFold - -# kfold is an instance initialized above as: -# kfold = KFold(n_splits = k) - -estimated_mse_sklearn = np.zeros(nlambdas) -i = 0 -for lmb in lambdas: - ridge = Ridge(alpha = lmb) - - X = poly.fit_transform(x[:, np.newaxis]) - estimated_mse_folds = cross_val_score(ridge, X, y[:, np.newaxis], scoring='neg_mean_squared_error', cv=kfold) - - # cross_val_score return an array containing the estimated negative mse for every fold. - # we have to the the mean of every array in order to get an estimate of the mse of the model - estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds) - - i += 1 - -## Plot and compare the slightly different ways to perform cross-validation - -plt.figure() - -plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score') -plt.plot(np.log10(lambdas), estimated_mse_KFold, 'r--', label = 'KFold') - -plt.xlabel('log10(lambda)') -plt.ylabel('mse') - -plt.legend() - -plt.show() -
    -

    diff --git a/doc/pub/week36/html/._week36-bs068.html b/doc/pub/week36/html/._week36-bs068.html index 1a932097e..4882d6442 100644 --- a/doc/pub/week36/html/._week36-bs068.html +++ b/doc/pub/week36/html/._week36-bs068.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,69 +383,103 @@ MathJax.Hub.Config({ -

    The bias-variance tradeoff

    +

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

    -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{L} \) consisting of the data -\( \mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). - +The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial.

    -Let us assume that the true data is generated from a noisy model -$$ -\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} -$$ + +

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import KFold
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import cross_val_score
    +from sklearn.preprocessing import PolynomialFeatures
     
    -

    -where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \). +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. +np.random.seed(3155) -

    -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} \). +# Generate the data. +nsamples = 100 +x = np.random.randn(nsamples) +y = 3*x**2 + np.random.randn(nsamples) -

    -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]. -$$ +## Cross-validation on Ridge regression using KFold only -

    -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. -$$ +# Decide degree on polynomial to fit +poly = PolynomialFeatures(degree = 6) -

    -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} \). +# Decide which values of lambda to use +nlambdas = 500 +lambdas = np.logspace(-3, 5, nlambdas) -

    -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], -$$ +# Initialize a KFold instance +k = 5 +kfold = KFold(n_splits = k) -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], -$$ +# Perform the cross-validation to estimate MSE +scores_KFold = np.zeros((nlambdas, k)) -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, -$$ +i = 0 +for lmb in lambdas: + ridge = Ridge(alpha = lmb) + j = 0 + for train_inds, test_inds in kfold.split(x): + xtrain = x[train_inds] + ytrain = y[train_inds] -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} \). + xtest = x[test_inds] + ytest = y[test_inds] + Xtrain = poly.fit_transform(xtrain[:, np.newaxis]) + ridge.fit(Xtrain, ytrain[:, np.newaxis]) + + Xtest = poly.fit_transform(xtest[:, np.newaxis]) + ypred = ridge.predict(Xtest) + + scores_KFold[i,j] = np.sum((ypred - ytest[:, np.newaxis])**2)/np.size(ypred) + + j += 1 + i += 1 + + +estimated_mse_KFold = np.mean(scores_KFold, axis = 1) + +## Cross-validation using cross_val_score from sklearn along with KFold + +# kfold is an instance initialized above as: +# kfold = KFold(n_splits = k) + +estimated_mse_sklearn = np.zeros(nlambdas) +i = 0 +for lmb in lambdas: + ridge = Ridge(alpha = lmb) + + X = poly.fit_transform(x[:, np.newaxis]) + estimated_mse_folds = cross_val_score(ridge, X, y[:, np.newaxis], scoring='neg_mean_squared_error', cv=kfold) + + # cross_val_score return an array containing the estimated negative mse for every fold. + # we have to the the mean of every array in order to get an estimate of the mse of the model + estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds) + + i += 1 + +## Plot and compare the slightly different ways to perform cross-validation + +plt.figure() + +plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score') +plt.plot(np.log10(lambdas), estimated_mse_KFold, 'r--', label = 'KFold') + +plt.xlabel('log10(lambda)') +plt.ylabel('mse') + +plt.legend() + +plt.show() +

    @@ -467,6 +503,7 @@ that is the rewriting in terms of the so-called bias, the variance of the model

  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs069.html b/doc/pub/week36/html/._week36-bs069.html index 7a8735a65..2676a63f0 100644 --- a/doc/pub/week36/html/._week36-bs069.html +++ b/doc/pub/week36/html/._week36-bs069.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,65 +383,69 @@ MathJax.Hub.Config({ -

    Example code for Bias-Variance tradeoff

    +

    The bias-variance tradeoff

    +

    +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{L} \) consisting of the data +\( \mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \). - -

    import matplotlib.pyplot as plt
    -import numpy as np
    -from sklearn.linear_model import LinearRegression, Ridge, Lasso
    -from sklearn.preprocessing import PolynomialFeatures
    -from sklearn.model_selection import train_test_split
    -from sklearn.pipeline import make_pipeline
    -from sklearn.utils import resample
    +

    +Let us assume that the true data is generated from a noisy model -np.random.seed(2018) +$$ +\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} +$$ -n = 500 -n_boostraps = 100 -degree = 18 # A quite high value, just to show. -noise = 0.1 +

    +where \( \epsilon \) is normally distributed with mean zero and standard deviation \( \sigma^2 \). -# Make data set. -x = np.linspace(-1, 3, n).reshape(-1, 1) -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) + np.random.normal(0, 0.1, x.shape) +

    +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} \). -# Hold out some test data that is never used in training. -x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) +

    +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]. +$$ -# Combine x transformation and model into one operation. -# Not neccesary, but convenient. -model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) +

    +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 following (m x n_bootstraps) matrix holds the column vectors y_pred -# for each bootstrap iteration. -y_pred = np.empty((y_test.shape[0], n_boostraps)) -for i in range(n_boostraps): - x_, y_ = resample(x_train, y_train) +

    +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} \). - # Evaluate the new model on the same test data each time. - y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() +

    +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], +$$ -# Note: Expectations and variances taken w.r.t. different training -# data sets, hence the axis=1. Subsequent means are taken across the test data -# set in order to obtain a total value, but before this we have error/bias/variance -# calculated per data point in the test set. -# Note 2: The use of keepdims=True is important in the calculation of bias as this -# maintains the column vector form. Dropping this yields very unexpected results. -error = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) -bias = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) -variance = np.mean( np.var(y_pred, axis=1, keepdims=True) ) -print('Error:', error) -print('Bias^2:', bias) -print('Var:', variance) -print('{} >= {} + {} = {}'.format(error, bias, variance, bias+variance)) +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 +$$ +\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} \). -plt.plot(x[::5, :], y[::5, :], label='f(x)') -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() -

    @@ -462,6 +468,7 @@ plt.show()

  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs070.html b/doc/pub/week36/html/._week36-bs070.html index 737d17777..12fc151d8 100644 --- a/doc/pub/week36/html/._week36-bs070.html +++ b/doc/pub/week36/html/._week36-bs070.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,7 +383,7 @@ MathJax.Hub.Config({ -

    Understanding what happens

    +

    Example code for Bias-Variance tradeoff

    @@ -395,40 +397,48 @@ MathJax.Hub.Config({ np.random.seed(2018) -n = 40 +n = 500 n_boostraps = 100 -maxdegree = 14 - +degree = 18 # A quite high value, just to show. +noise = 0.1 # Make data set. -x = np.linspace(-3, 3, n).reshape(-1, 1) -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape) -error = np.zeros(maxdegree) -bias = np.zeros(maxdegree) -variance = np.zeros(maxdegree) -polydegree = np.zeros(maxdegree) +x = np.linspace(-1, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) + np.random.normal(0, 0.1, x.shape) + +# Hold out some test data that is never used in training. x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) -for degree in range(maxdegree): - model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) - y_pred = np.empty((y_test.shape[0], n_boostraps)) - for i in range(n_boostraps): - x_, y_ = resample(x_train, y_train) - y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() +# Combine x transformation and model into one operation. +# Not neccesary, but convenient. +model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) - polydegree[degree] = degree - error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) - bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) - variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) ) - print('Polynomial degree:', degree) - print('Error:', error[degree]) - print('Bias^2:', bias[degree]) - print('Var:', variance[degree]) - print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree])) +# The following (m x n_bootstraps) matrix holds the column vectors y_pred +# for each bootstrap iteration. +y_pred = np.empty((y_test.shape[0], n_boostraps)) +for i in range(n_boostraps): + x_, y_ = resample(x_train, y_train) -plt.plot(polydegree, error, label='Error') -plt.plot(polydegree, bias, label='bias') -plt.plot(polydegree, variance, label='Variance') + # Evaluate the new model on the same test data each time. + y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() + +# Note: Expectations and variances taken w.r.t. different training +# data sets, hence the axis=1. Subsequent means are taken across the test data +# set in order to obtain a total value, but before this we have error/bias/variance +# calculated per data point in the test set. +# Note 2: The use of keepdims=True is important in the calculation of bias as this +# maintains the column vector form. Dropping this yields very unexpected results. +error = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) +bias = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) +variance = np.mean( np.var(y_pred, axis=1, keepdims=True) ) +print('Error:', error) +print('Bias^2:', bias) +print('Var:', variance) +print('{} >= {} + {} = {}'.format(error, bias, variance, bias+variance)) + +plt.plot(x[::5, :], y[::5, :], label='f(x)') +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()

    @@ -453,6 +463,7 @@ plt.show()
  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs071.html b/doc/pub/week36/html/._week36-bs071.html index c4d145d25..84c0e2e7f 100644 --- a/doc/pub/week36/html/._week36-bs071.html +++ b/doc/pub/week36/html/._week36-bs071.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,42 +381,59 @@ MathJax.Hub.Config({

     

     

     

    - - -

    Summing up

    + +

    Understanding what happens

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

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

    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.linear_model import LinearRegression, Ridge, Lasso
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.model_selection import train_test_split
    +from sklearn.pipeline import make_pipeline
    +from sklearn.utils import resample
     
    -

    -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 -training data sets will result in a different estimate. But ideally the -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. +np.random.seed(2018) -

    -You may also find this recent article of interest. +n = 40 +n_boostraps = 100 +maxdegree = 14 + +# Make data set. +x = np.linspace(-3, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape) +error = np.zeros(maxdegree) +bias = np.zeros(maxdegree) +variance = np.zeros(maxdegree) +polydegree = np.zeros(maxdegree) +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) + +for degree in range(maxdegree): + model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) + y_pred = np.empty((y_test.shape[0], n_boostraps)) + for i in range(n_boostraps): + x_, y_ = resample(x_train, y_train) + y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() + + polydegree[degree] = degree + error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) + bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) + variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) ) + print('Polynomial degree:', degree) + print('Error:', error[degree]) + print('Bias^2:', bias[degree]) + print('Var:', variance[degree]) + print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree])) + +plt.plot(polydegree, error, label='Error') +plt.plot(polydegree, bias, label='bias') +plt.plot(polydegree, variance, label='Variance') +plt.legend() +plt.show() +

    @@ -435,6 +454,7 @@ You may also find this recent 74

  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs072.html b/doc/pub/week36/html/._week36-bs072.html index b6f2c5bff..42f7ab9b6 100644 --- a/doc/pub/week36/html/._week36-bs072.html +++ b/doc/pub/week36/html/._week36-bs072.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,84 +381,42 @@ MathJax.Hub.Config({

     

     

     

    - + + +

    Summing up

    -

    Another Example from Scikit-Learn's Repository

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

    """
    -============================
    -Underfitting vs. Overfitting
    -============================
    +

    +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. -This example demonstrates the problems of underfitting and overfitting and -how we can use linear regression with polynomial features to approximate -nonlinear functions. The plot shows the function that we want to approximate, -which is a part of the cosine function. In addition, the samples from the -real function and the approximations of different models are displayed. The -models have polynomial features of different degrees. We can see that a -linear function (polynomial with degree 1) is not sufficient to fit the -training samples. This is called **underfitting**. A polynomial of degree 4 -approximates the true function almost perfectly. However, for higher degrees -the model will **overfit** the training data, i.e. it learns the noise of the -training data. -We evaluate quantitatively **overfitting** / **underfitting** by using -cross-validation. We calculate the mean squared error (MSE) on the validation -set, the higher, the less likely the model generalizes correctly from the -training data. -""" +

    +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 +training data sets will result in a different estimate. But ideally the +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. -print(__doc__) +

    +You may also find this recent article of interest. -import numpy as np -import matplotlib.pyplot as plt -from sklearn.pipeline import Pipeline -from sklearn.preprocessing import PolynomialFeatures -from sklearn.linear_model import LinearRegression -from sklearn.model_selection import cross_val_score - - -def true_fun(X): - return np.cos(1.5 * np.pi * X) - -np.random.seed(0) - -n_samples = 30 -degrees = [1, 4, 15] - -X = np.sort(np.random.rand(n_samples)) -y = true_fun(X) + np.random.randn(n_samples) * 0.1 - -plt.figure(figsize=(14, 5)) -for i in range(len(degrees)): - ax = plt.subplot(1, len(degrees), i + 1) - plt.setp(ax, xticks=(), yticks=()) - - polynomial_features = PolynomialFeatures(degree=degrees[i], - include_bias=False) - linear_regression = LinearRegression() - pipeline = Pipeline([("polynomial_features", polynomial_features), - ("linear_regression", linear_regression)]) - pipeline.fit(X[:, np.newaxis], y) - - # Evaluate the models using crossvalidation - scores = cross_val_score(pipeline, X[:, np.newaxis], y, - scoring="neg_mean_squared_error", cv=10) - - X_test = np.linspace(0, 1, 100) - plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label="Model") - plt.plot(X_test, true_fun(X_test), label="True function") - plt.scatter(X, y, edgecolor='b', s=20, label="Samples") - plt.xlabel("x") - plt.ylabel("y") - plt.xlim((0, 1)) - plt.ylim((-2, 2)) - plt.legend(loc="best") - plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format( - degrees[i], -scores.mean(), scores.std())) -plt.show() -

    @@ -476,6 +436,7 @@ plt.show()

  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs073.html b/doc/pub/week36/html/._week36-bs073.html index da8f6d8d9..9539b9b4c 100644 --- a/doc/pub/week36/html/._week36-bs073.html +++ b/doc/pub/week36/html/._week36-bs073.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -381,88 +383,80 @@ MathJax.Hub.Config({ -

    More examples on bootstrap and cross-validation and errors

    - +

    Another Example from Scikit-Learn's Repository

    -

    # Common imports
    -import os
    +
    """
    +============================
    +Underfitting vs. Overfitting
    +============================
    +
    +This example demonstrates the problems of underfitting and overfitting and
    +how we can use linear regression with polynomial features to approximate
    +nonlinear functions. The plot shows the function that we want to approximate,
    +which is a part of the cosine function. In addition, the samples from the
    +real function and the approximations of different models are displayed. The
    +models have polynomial features of different degrees. We can see that a
    +linear function (polynomial with degree 1) is not sufficient to fit the
    +training samples. This is called **underfitting**. A polynomial of degree 4
    +approximates the true function almost perfectly. However, for higher degrees
    +the model will **overfit** the training data, i.e. it learns the noise of the
    +training data.
    +We evaluate quantitatively **overfitting** / **underfitting** by using
    +cross-validation. We calculate the mean squared error (MSE) on the validation
    +set, the higher, the less likely the model generalizes correctly from the
    +training data.
    +"""
    +
    +print(__doc__)
    +
     import numpy as np
    -import pandas as pd
     import matplotlib.pyplot as plt
    -from sklearn.linear_model import LinearRegression, Ridge, Lasso
    -from sklearn.model_selection import train_test_split
    -from sklearn.utils import resample
    -from sklearn.metrics import mean_squared_error
    -# Where to save the figures and data files
    -PROJECT_ROOT_DIR = "Results"
    -FIGURE_ID = "Results/FigureFiles"
    -DATA_ID = "DataFiles/"
    +from sklearn.pipeline import Pipeline
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.linear_model import LinearRegression
    +from sklearn.model_selection import cross_val_score
     
    -if not os.path.exists(PROJECT_ROOT_DIR):
    -    os.mkdir(PROJECT_ROOT_DIR)
     
    -if not os.path.exists(FIGURE_ID):
    -    os.makedirs(FIGURE_ID)
    +def true_fun(X):
    +    return np.cos(1.5 * np.pi * X)
     
    -if not os.path.exists(DATA_ID):
    -    os.makedirs(DATA_ID)
    +np.random.seed(0)
     
    -def image_path(fig_id):
    -    return os.path.join(FIGURE_ID, fig_id)
    +n_samples = 30
    +degrees = [1, 4, 15]
     
    -def data_path(dat_id):
    -    return os.path.join(DATA_ID, dat_id)
    +X = np.sort(np.random.rand(n_samples))
    +y = true_fun(X) + np.random.randn(n_samples) * 0.1
     
    -def save_fig(fig_id):
    -    plt.savefig(image_path(fig_id) + ".png", format='png')
    +plt.figure(figsize=(14, 5))
    +for i in range(len(degrees)):
    +    ax = plt.subplot(1, len(degrees), i + 1)
    +    plt.setp(ax, xticks=(), yticks=())
     
    -infile = open(data_path("EoS.csv"),'r')
    +    polynomial_features = PolynomialFeatures(degree=degrees[i],
    +                                             include_bias=False)
    +    linear_regression = LinearRegression()
    +    pipeline = Pipeline([("polynomial_features", polynomial_features),
    +                         ("linear_regression", linear_regression)])
    +    pipeline.fit(X[:, np.newaxis], y)
     
    -# Read the EoS data as  csv file and organize the data into two arrays with density and energies
    -EoS = pd.read_csv(infile, names=('Density', 'Energy'))
    -EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce')
    -EoS = EoS.dropna()
    -Energies = EoS['Energy']
    -Density = EoS['Density']
    -#  The design matrix now as function of various polytrops
    +    # Evaluate the models using crossvalidation
    +    scores = cross_val_score(pipeline, X[:, np.newaxis], y,
    +                             scoring="neg_mean_squared_error", cv=10)
     
    -Maxpolydegree = 30
    -X = np.zeros((len(Density),Maxpolydegree))
    -X[:,0] = 1.0
    -testerror = np.zeros(Maxpolydegree)
    -trainingerror = np.zeros(Maxpolydegree)
    -polynomial = np.zeros(Maxpolydegree)
    -
    -trials = 100
    -for polydegree in range(1, Maxpolydegree):
    -    polynomial[polydegree] = polydegree
    -    for degree in range(polydegree):
    -        X[:,degree] = Density**(degree/3.0)
    -
    -# loop over trials in order to estimate the expectation value of the MSE
    -    testerror[polydegree] = 0.0
    -    trainingerror[polydegree] = 0.0
    -    for samples in range(trials):
    -        x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2)
    -        model = LinearRegression(fit_intercept=True).fit(x_train, y_train)
    -        ypred = model.predict(x_train)
    -        ytilde = model.predict(x_test)
    -        testerror[polydegree] += mean_squared_error(y_test, ytilde)
    -        trainingerror[polydegree] += mean_squared_error(y_train, ypred) 
    -
    -    testerror[polydegree] /= trials
    -    trainingerror[polydegree] /= trials
    -    print("Degree of polynomial: %3d"% polynomial[polydegree])
    -    print("Mean squared error on training data: %.8f" % trainingerror[polydegree])
    -    print("Mean squared error on test data: %.8f" % testerror[polydegree])
    -
    -plt.plot(polynomial, np.log10(trainingerror), label='Training Error')
    -plt.plot(polynomial, np.log10(testerror), label='Test Error')
    -plt.xlabel('Polynomial degree')
    -plt.ylabel('log10[MSE]')
    -plt.legend()
    +    X_test = np.linspace(0, 1, 100)
    +    plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label="Model")
    +    plt.plot(X_test, true_fun(X_test), label="True function")
    +    plt.scatter(X, y, edgecolor='b', s=20, label="Samples")
    +    plt.xlabel("x")
    +    plt.ylabel("y")
    +    plt.xlim((0, 1))
    +    plt.ylim((-2, 2))
    +    plt.legend(loc="best")
    +    plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
    +        degrees[i], -scores.mean(), scores.std()))
     plt.show()
     

    @@ -483,6 +477,7 @@ plt.show()

  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs074.html b/doc/pub/week36/html/._week36-bs074.html index 549141174..94f5a51d0 100644 --- a/doc/pub/week36/html/._week36-bs074.html +++ b/doc/pub/week36/html/._week36-bs074.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,9 +381,9 @@ MathJax.Hub.Config({

     

     

     

    - + -

    The same example but now with cross-validation

    +

    More examples on bootstrap and cross-validation and errors

    @@ -392,11 +394,9 @@ MathJax.Hub.Config({ import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression, Ridge, Lasso +from sklearn.model_selection import train_test_split +from sklearn.utils import resample from sklearn.metrics import mean_squared_error -from sklearn.model_selection import KFold -from sklearn.model_selection import cross_val_score - - # Where to save the figures and data files PROJECT_ROOT_DIR = "Results" FIGURE_ID = "Results/FigureFiles" @@ -433,22 +433,35 @@ Density = EoS[& Maxpolydegree = 30 X = np.zeros((len(Density),Maxpolydegree)) X[:,0] = 1.0 -estimated_mse_sklearn = np.zeros(Maxpolydegree) +testerror = np.zeros(Maxpolydegree) +trainingerror = np.zeros(Maxpolydegree) polynomial = np.zeros(Maxpolydegree) -k =5 -kfold = KFold(n_splits = k) +trials = 100 for polydegree in range(1, Maxpolydegree): polynomial[polydegree] = polydegree for degree in range(polydegree): X[:,degree] = Density**(degree/3.0) - OLS = LinearRegression() -# loop over trials in order to estimate the expectation value of the MSE - estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring='neg_mean_squared_error', cv=kfold) -#[:, np.newaxis] - estimated_mse_sklearn[polydegree] = np.mean(-estimated_mse_folds) -plt.plot(polynomial, np.log10(estimated_mse_sklearn), label='Test Error') +# loop over trials in order to estimate the expectation value of the MSE + testerror[polydegree] = 0.0 + trainingerror[polydegree] = 0.0 + for samples in range(trials): + x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2) + model = LinearRegression(fit_intercept=True).fit(x_train, y_train) + ypred = model.predict(x_train) + ytilde = model.predict(x_test) + testerror[polydegree] += mean_squared_error(y_test, ytilde) + trainingerror[polydegree] += mean_squared_error(y_train, ypred) + + testerror[polydegree] /= trials + trainingerror[polydegree] /= trials + print("Degree of polynomial: %3d"% polynomial[polydegree]) + print("Mean squared error on training data: %.8f" % trainingerror[polydegree]) + print("Mean squared error on test data: %.8f" % testerror[polydegree]) + +plt.plot(polynomial, np.log10(trainingerror), label='Training Error') +plt.plot(polynomial, np.log10(testerror), label='Test Error') plt.xlabel('Polynomial degree') plt.ylabel('log10[MSE]') plt.legend() @@ -471,6 +484,7 @@ plt.show()

  • 74
  • 75
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/._week36-bs075.html b/doc/pub/week36/html/._week36-bs075.html index b6a328b71..4e6e96557 100644 --- a/doc/pub/week36/html/._week36-bs075.html +++ b/doc/pub/week36/html/._week36-bs075.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -379,50 +381,82 @@ MathJax.Hub.Config({

     

     

     

    - + + +

    The same example but now with cross-validation

    -

    Cross-validation with Ridge

    -

    import numpy as np
    +
    # Common imports
    +import os
    +import numpy as np
    +import pandas as pd
     import matplotlib.pyplot as plt
    +from sklearn.linear_model import LinearRegression, Ridge, Lasso
    +from sklearn.metrics import mean_squared_error
     from sklearn.model_selection import KFold
    -from sklearn.linear_model import Ridge
     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.
    -np.random.seed(3155)
    -# Generate the data.
    -n = 100
    -x = np.linspace(-3, 3, n).reshape(-1, 1)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    -# Decide degree on polynomial to fit
    -poly = PolynomialFeatures(degree = 10)
     
    -# Decide which values of lambda to use
    -nlambdas = 500
    -lambdas = np.logspace(-3, 5, nlambdas)
    -# Initialize a KFold instance
    -k = 5
    +# Where to save the figures and data files
    +PROJECT_ROOT_DIR = "Results"
    +FIGURE_ID = "Results/FigureFiles"
    +DATA_ID = "DataFiles/"
    +
    +if not os.path.exists(PROJECT_ROOT_DIR):
    +    os.mkdir(PROJECT_ROOT_DIR)
    +
    +if not os.path.exists(FIGURE_ID):
    +    os.makedirs(FIGURE_ID)
    +
    +if not os.path.exists(DATA_ID):
    +    os.makedirs(DATA_ID)
    +
    +def image_path(fig_id):
    +    return os.path.join(FIGURE_ID, fig_id)
    +
    +def data_path(dat_id):
    +    return os.path.join(DATA_ID, dat_id)
    +
    +def save_fig(fig_id):
    +    plt.savefig(image_path(fig_id) + ".png", format='png')
    +
    +infile = open(data_path("EoS.csv"),'r')
    +
    +# Read the EoS data as  csv file and organize the data into two arrays with density and energies
    +EoS = pd.read_csv(infile, names=('Density', 'Energy'))
    +EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce')
    +EoS = EoS.dropna()
    +Energies = EoS['Energy']
    +Density = EoS['Density']
    +#  The design matrix now as function of various polytrops
    +
    +Maxpolydegree = 30
    +X = np.zeros((len(Density),Maxpolydegree))
    +X[:,0] = 1.0
    +estimated_mse_sklearn = np.zeros(Maxpolydegree)
    +polynomial = np.zeros(Maxpolydegree)
    +k =5
     kfold = KFold(n_splits = k)
    -estimated_mse_sklearn = np.zeros(nlambdas)
    -i = 0
    -for lmb in lambdas:
    -    ridge = Ridge(alpha = lmb)
    -    estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)
    -    estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
    -    i += 1
    -plt.figure()
    -plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
    -plt.xlabel('log10(lambda)')
    -plt.ylabel('MSE')
    +
    +for polydegree in range(1, Maxpolydegree):
    +    polynomial[polydegree] = polydegree
    +    for degree in range(polydegree):
    +        X[:,degree] = Density**(degree/3.0)
    +        OLS = LinearRegression()
    +# loop over trials in order to estimate the expectation value of the MSE
    +    estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring='neg_mean_squared_error', cv=kfold)
    +#[:, np.newaxis]
    +    estimated_mse_sklearn[polydegree] = np.mean(-estimated_mse_folds)
    +
    +plt.plot(polynomial, np.log10(estimated_mse_sklearn), label='Test Error')
    +plt.xlabel('Polynomial degree')
    +plt.ylabel('log10[MSE]')
     plt.legend()
     plt.show()
     

    -

      @@ -438,6 +472,8 @@ plt.show()
    • 74
    • 75
    • 76
    • +
    • 77
    • +
    • »
    diff --git a/doc/pub/week36/html/week36-bs.html b/doc/pub/week36/html/week36-bs.html index b7fdad551..6ae16d98c 100644 --- a/doc/pub/week36/html/week36-bs.html +++ b/doc/pub/week36/html/week36-bs.html @@ -111,6 +111,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -318,54 +319,55 @@ MathJax.Hub.Config({
  • Simple code for solving the above problem
  • With Lasso Regression
  • Another Example, now with a polynomial fit
  • -
  • Friday September 10
  • -
  • Linking the regression analysis with a statistical interpretation
  • -
  • Assumptions made
  • -
  • Expectation value and variance
  • -
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • -
  • Deriving OLS from a probability distribution
  • -
  • Independent and Identically Distrubuted (iid)
  • -
  • Maximum Likelihood Estimation (MLE)
  • -
  • A new Cost Function
  • -
  • More basic Statistics and Bayes' theorem
  • -
  • Marginal Probability
  • -
  • Conditional Probability
  • -
  • Bayes' Theorem
  • -
  • Interpretations of Bayes' Theorem
  • -
  • Example of Usage of Bayes' theorem
  • -
  • Doing it correctly
  • -
  • Bayes' Theorem and Ridge and Lasso Regression
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Invoking Bayes' theorem
  • -
  • Ridge and Bayes
  • -
  • Lasso and Bayes
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Using CVXOPT
  • +
  • Friday September 10
  • +
  • Linking the regression analysis with a statistical interpretation
  • +
  • Assumptions made
  • +
  • Expectation value and variance
  • +
  • Expectation value and variance for \( \boldsymbol{\beta} \)
  • +
  • Deriving OLS from a probability distribution
  • +
  • Independent and Identically Distrubuted (iid)
  • +
  • Maximum Likelihood Estimation (MLE)
  • +
  • A new Cost Function
  • +
  • More basic Statistics and Bayes' theorem
  • +
  • Marginal Probability
  • +
  • Conditional Probability
  • +
  • Bayes' Theorem
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Bayes' Theorem and Ridge and Lasso Regression
  • +
  • Test Function for what happens with OLS, Ridge and Lasso
  • +
  • Invoking Bayes' theorem
  • +
  • Ridge and Bayes
  • +
  • Lasso and Bayes
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -400,7 +402,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 10, 2021

    +

    Sep 12, 2021


    @@ -424,7 +426,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 76
  • +
  • 77
  • »
  • diff --git a/doc/pub/week36/html/week36-reveal.html b/doc/pub/week36/html/week36-reveal.html index c4ca4f518..387a4be06 100644 --- a/doc/pub/week36/html/week36-reveal.html +++ b/doc/pub/week36/html/week36-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

     
    -

    Sep 10, 2021

    +

    Sep 12, 2021


    @@ -1188,6 +1188,290 @@ plt.show() +

    +

    Using CVXOPT

    + +

    +As a small addendum, we note that you can also solve this problem +using the convex optimization package +CVXOPT. This +requires, in addition to having installed CVXOPT, you need to +download the file l1regl.py. The following code example solves the +simpler problem we discussed above, where we have added the latter +python file. + +

    + + +

    from l1regls import l1regls
    +from cvxopt import matrix, normal
    +import numpy as np
    +
    +X = matrix( [ [ 2, 0, 1], [0, 1, 3]])
    +y = matrix( [4, 2, 3])
    +x = l1regls(X,y)
    +
    +from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed
    +from cvxopt import blas, lapack, solvers, sparse, spmatrix
    +import math
    +
    +try:
    +    import mosek
    +    import sys
    +    __MOSEK = True
    +except: __MOSEK = False
    +
    +if __MOSEK:
    +
    +    def l1regls_mosek(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize    || A*x - b ||_2^2  + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars( 2*n)            # number of variables
    +        task.appendcons( 2*n)            # number of constraints
    +
    +        # input quadratic objective
    +        Q = matrix(0.0, (n,n)) 
    +        blas.syrk(A, Q, alpha = 2.0, trans='T')
    +
    +        I = []
    +        for i in range(n):
    +            I.extend(range(i,n))
    +
    +        J = []
    +        for i in range(n):
    +            J.extend((n-i)*[i])
    +
    +        task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n]))
    +        task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var,
    +                           0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +    def l1regls_mosek2(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize     w'*w + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +                         A*x - w = b
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars(2*n + m)     # number of variables
    +        task.appendcons(2*n + m)     # number of constraints
    +
    +        # input quadratic objective
    +        task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0])
    +
    +        task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        for i in range(m):
    +            task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b))
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], 
    +                           (2*n+m)*[0.0], (2*n+m)*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +def l1regls(A, b):
    +    """
    +    
    +    Returns the solution of l1-norm regularized least-squares problem
    +  
    +        minimize || A*x - b ||_2^2  + || x ||_1.
    +
    +    """
    +
    +    m, n = A.size
    +    q = matrix(1.0, (2*n,1))
    +    q[:n] = -2.0 * A.T * b
    +
    +    def P(u, v, alpha = 1.0, beta = 0.0 ):
    +        """
    +            v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v 
    +        """
    +        v *= beta
    +        v[:n] += alpha * 2.0 * A.T * (A * u[:n])
    +
    +
    +    def G(u, v, alpha=1.0, beta=0.0, trans='N'):
    +        """
    +            v := alpha*[I, -I; -I, -I] * u + beta * v  (trans = 'N' or 'T')
    +        """
    +
    +        v *= beta
    +        v[:n] += alpha*(u[:n] - u[n:])
    +        v[n:] += alpha*(-u[:n] - u[n:])
    +
    +    h = matrix(0.0, (2*n,1))
    +
    +
    +    # Customized solver for the KKT system 
    +    #
    +    #     [  2.0*A'*A  0    I      -I     ] [x[:n] ]     [bx[:n] ]
    +    #     [  0         0   -I      -I     ] [x[n:] ]  =  [bx[n:] ].
    +    #     [  I        -I   -D1^-1   0     ] [zl[:n]]     [bzl[:n]]
    +    #     [ -I        -I    0      -D2^-1 ] [zl[n:]]     [bzl[n:]]
    +    #
    +    # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2.
    +    #    
    +    # We first eliminate zl and x[n:]:
    +    #
    +    #     ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = 
    +    #         bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +    #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +    #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:]           
    +    #
    +    #     x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +    #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +    #
    +    #     zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] )
    +    #     zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ).
    +    #
    +    # The first equation has the form
    +    #
    +    #     (A'*A + D)*x[:n]  =  rhs
    +    #
    +    # and is equivalent to
    +    #
    +    #     [ D    A' ] [ x:n] ]  = [ rhs ]
    +    #     [ A   -I  ] [ v    ]    [ 0   ].
    +    #
    +    # It can be solved as 
    +    #
    +    #     ( A*D^-1*A' + I ) * v = A * D^-1 * rhs
    +    #     x[:n] = D^-1 * ( rhs - A'*v ).
    +
    +    S = matrix(0.0, (m,m))
    +    Asc = matrix(0.0, (m,n))
    +    v = matrix(0.0, (m,1))
    +
    +    def Fkkt(W):
    +
    +        # Factor 
    +        #
    +        #     S = A*D^-1*A' + I 
    +        #
    +        # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2.
    +
    +        d1, d2 = W['di'][:n]**2, W['di'][n:]**2
    +
    +        # ds is square root of diagonal of D
    +        ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), 
    +            sqrt(d1+d2) )
    +        d3 =  div(d2 - d1, d1 + d2)
    +     
    +        # Asc = A*diag(d)^-1/2
    +        Asc = A * spdiag(ds**-1)
    +
    +        # S = I + A * D^-1 * A'
    +        blas.syrk(Asc, S)
    +        S[::m+1] += 1.0 
    +        lapack.potrf(S)
    +
    +        def g(x, y, z):
    +
    +            x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + 
    +                mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - 
    +                mul(d3, z[n:])) )
    +            x[:n] = div( x[:n], ds) 
    +
    +            # Solve
    +            #
    +            #     S * v = 0.5 * A * D^-1 * ( bx[:n] - 
    +            #         (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +            #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +            #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] )
    +                
    +            blas.gemv(Asc, x, v)
    +            lapack.potrs(S, v)
    +            
    +            # x[:n] = D^-1 * ( rhs - A'*v ).
    +            blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')
    +            x[:n] = div(x[:n], ds)
    +
    +            # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +            #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +            x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\
    +                - mul( d3, x[:n] )
    +                
    +            # zl[:n] = D1^1/2 * (  x[:n] - x[n:] - bzl[:n] )
    +            # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ).
    +            z[:n] = mul( W['di'][:n],  x[:n] - x[n:] - z[:n] ) 
    +            z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) 
    +
    +        return g
    +
    +    return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n]
    +
    +
    + +

    Friday September 10

    diff --git a/doc/pub/week36/html/week36-solarized.html b/doc/pub/week36/html/week36-solarized.html index 160a6e29d..e202e4869 100644 --- a/doc/pub/week36/html/week36-solarized.html +++ b/doc/pub/week36/html/week36-solarized.html @@ -131,6 +131,7 @@ div { text-align: justify; text-justify: inter-word; } 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -315,7 +316,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 10, 2021

    +

    Sep 12, 2021












    @@ -1230,6 +1231,289 @@ plt.show()











    +

    Using CVXOPT

    + +

    +As a small addendum, we note that you can also solve this problem +using the convex optimization package +CVXOPT. This +requires, in addition to having installed CVXOPT, you need to +download the file l1regl.py. The following code example solves the +simpler problem we discussed above, where we have added the latter +python file. + +

    + + +

    from l1regls import l1regls
    +from cvxopt import matrix, normal
    +import numpy as np
    +
    +X = matrix( [ [ 2, 0, 1], [0, 1, 3]])
    +y = matrix( [4, 2, 3])
    +x = l1regls(X,y)
    +
    +from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed
    +from cvxopt import blas, lapack, solvers, sparse, spmatrix
    +import math
    +
    +try:
    +    import mosek
    +    import sys
    +    __MOSEK = True
    +except: __MOSEK = False
    +
    +if __MOSEK:
    +
    +    def l1regls_mosek(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize    || A*x - b ||_2^2  + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars( 2*n)            # number of variables
    +        task.appendcons( 2*n)            # number of constraints
    +
    +        # input quadratic objective
    +        Q = matrix(0.0, (n,n)) 
    +        blas.syrk(A, Q, alpha = 2.0, trans='T')
    +
    +        I = []
    +        for i in range(n):
    +            I.extend(range(i,n))
    +
    +        J = []
    +        for i in range(n):
    +            J.extend((n-i)*[i])
    +
    +        task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n]))
    +        task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var,
    +                           0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +    def l1regls_mosek2(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize     w'*w + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +                         A*x - w = b
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars(2*n + m)     # number of variables
    +        task.appendcons(2*n + m)     # number of constraints
    +
    +        # input quadratic objective
    +        task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0])
    +
    +        task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        for i in range(m):
    +            task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b))
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], 
    +                           (2*n+m)*[0.0], (2*n+m)*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +def l1regls(A, b):
    +    """
    +    
    +    Returns the solution of l1-norm regularized least-squares problem
    +  
    +        minimize || A*x - b ||_2^2  + || x ||_1.
    +
    +    """
    +
    +    m, n = A.size
    +    q = matrix(1.0, (2*n,1))
    +    q[:n] = -2.0 * A.T * b
    +
    +    def P(u, v, alpha = 1.0, beta = 0.0 ):
    +        """
    +            v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v 
    +        """
    +        v *= beta
    +        v[:n] += alpha * 2.0 * A.T * (A * u[:n])
    +
    +
    +    def G(u, v, alpha=1.0, beta=0.0, trans='N'):
    +        """
    +            v := alpha*[I, -I; -I, -I] * u + beta * v  (trans = 'N' or 'T')
    +        """
    +
    +        v *= beta
    +        v[:n] += alpha*(u[:n] - u[n:])
    +        v[n:] += alpha*(-u[:n] - u[n:])
    +
    +    h = matrix(0.0, (2*n,1))
    +
    +
    +    # Customized solver for the KKT system 
    +    #
    +    #     [  2.0*A'*A  0    I      -I     ] [x[:n] ]     [bx[:n] ]
    +    #     [  0         0   -I      -I     ] [x[n:] ]  =  [bx[n:] ].
    +    #     [  I        -I   -D1^-1   0     ] [zl[:n]]     [bzl[:n]]
    +    #     [ -I        -I    0      -D2^-1 ] [zl[n:]]     [bzl[n:]]
    +    #
    +    # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2.
    +    #    
    +    # We first eliminate zl and x[n:]:
    +    #
    +    #     ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = 
    +    #         bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +    #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +    #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:]           
    +    #
    +    #     x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +    #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +    #
    +    #     zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] )
    +    #     zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ).
    +    #
    +    # The first equation has the form
    +    #
    +    #     (A'*A + D)*x[:n]  =  rhs
    +    #
    +    # and is equivalent to
    +    #
    +    #     [ D    A' ] [ x:n] ]  = [ rhs ]
    +    #     [ A   -I  ] [ v    ]    [ 0   ].
    +    #
    +    # It can be solved as 
    +    #
    +    #     ( A*D^-1*A' + I ) * v = A * D^-1 * rhs
    +    #     x[:n] = D^-1 * ( rhs - A'*v ).
    +
    +    S = matrix(0.0, (m,m))
    +    Asc = matrix(0.0, (m,n))
    +    v = matrix(0.0, (m,1))
    +
    +    def Fkkt(W):
    +
    +        # Factor 
    +        #
    +        #     S = A*D^-1*A' + I 
    +        #
    +        # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2.
    +
    +        d1, d2 = W['di'][:n]**2, W['di'][n:]**2
    +
    +        # ds is square root of diagonal of D
    +        ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), 
    +            sqrt(d1+d2) )
    +        d3 =  div(d2 - d1, d1 + d2)
    +     
    +        # Asc = A*diag(d)^-1/2
    +        Asc = A * spdiag(ds**-1)
    +
    +        # S = I + A * D^-1 * A'
    +        blas.syrk(Asc, S)
    +        S[::m+1] += 1.0 
    +        lapack.potrf(S)
    +
    +        def g(x, y, z):
    +
    +            x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + 
    +                mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - 
    +                mul(d3, z[n:])) )
    +            x[:n] = div( x[:n], ds) 
    +
    +            # Solve
    +            #
    +            #     S * v = 0.5 * A * D^-1 * ( bx[:n] - 
    +            #         (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +            #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +            #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] )
    +                
    +            blas.gemv(Asc, x, v)
    +            lapack.potrs(S, v)
    +            
    +            # x[:n] = D^-1 * ( rhs - A'*v ).
    +            blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')
    +            x[:n] = div(x[:n], ds)
    +
    +            # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +            #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +            x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\
    +                - mul( d3, x[:n] )
    +                
    +            # zl[:n] = D1^1/2 * (  x[:n] - x[n:] - bzl[:n] )
    +            # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ).
    +            z[:n] = mul( W['di'][:n],  x[:n] - x[n:] - z[:n] ) 
    +            z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) 
    +
    +        return g
    +
    +    return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n]
    +
    +

    +









    +

    Friday September 10

    diff --git a/doc/pub/week36/html/week36.html b/doc/pub/week36/html/week36.html index 00668148b..07a2f6b74 100644 --- a/doc/pub/week36/html/week36.html +++ b/doc/pub/week36/html/week36.html @@ -136,6 +136,7 @@ div { text-align: justify; text-justify: inter-word; } 2, None, 'another-example-now-with-a-polynomial-fit'), + ('Using CVXOPT', 2, None, 'using-cvxopt'), ('Friday September 10', 2, None, 'friday-september-10'), ('Linking the regression analysis with a statistical ' 'interpretation', @@ -320,7 +321,7 @@ MathJax.Hub.Config({

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

    -

    Sep 10, 2021

    +

    Sep 12, 2021












    @@ -1235,6 +1236,289 @@ plt.show()











    +

    Using CVXOPT

    + +

    +As a small addendum, we note that you can also solve this problem +using the convex optimization package +CVXOPT. This +requires, in addition to having installed CVXOPT, you need to +download the file l1regl.py. The following code example solves the +simpler problem we discussed above, where we have added the latter +python file. + +

    + + +

    from l1regls import l1regls
    +from cvxopt import matrix, normal
    +import numpy as np
    +
    +X = matrix( [ [ 2, 0, 1], [0, 1, 3]])
    +y = matrix( [4, 2, 3])
    +x = l1regls(X,y)
    +
    +from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed
    +from cvxopt import blas, lapack, solvers, sparse, spmatrix
    +import math
    +
    +try:
    +    import mosek
    +    import sys
    +    __MOSEK = True
    +except: __MOSEK = False
    +
    +if __MOSEK:
    +
    +    def l1regls_mosek(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize    || A*x - b ||_2^2  + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars( 2*n)            # number of variables
    +        task.appendcons( 2*n)            # number of constraints
    +
    +        # input quadratic objective
    +        Q = matrix(0.0, (n,n)) 
    +        blas.syrk(A, Q, alpha = 2.0, trans='T')
    +
    +        I = []
    +        for i in range(n):
    +            I.extend(range(i,n))
    +
    +        J = []
    +        for i in range(n):
    +            J.extend((n-i)*[i])
    +
    +        task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n]))
    +        task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var,
    +                           0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +    def l1regls_mosek2(A, b):
    +        """
    +
    +        Returns the solution of l1-norm regularized least-squares problem
    +
    +            minimize     w'*w + e'*u
    +
    +            subject to  -u <= x <= u
    +
    +                         A*x - w = b
    +
    +        """
    +
    +        m, n = A.size
    +
    +        env  = mosek.Env()
    +        task = env.Task(0,0)
    +        task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))
    +
    +        task.appendvars(2*n + m)     # number of variables
    +        task.appendcons(2*n + m)     # number of constraints
    +
    +        # input quadratic objective
    +        task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0])
    +
    +        task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0])  # setup linear objective
    +
    +        # input constraint matrix row by row
    +        for i in range(n):
    +            task.putarow(   i, [i, n+i], [1.0, -1.0])
    +            task.putarow( n+i, [i, n+i], [1.0,  1.0])
    +
    +        for i in range(m):
    +            task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0])
    +
    +        # setup bounds on constraints
    +        task.putboundslice(mosek.accmode.con,
    +                           0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])
    +        task.putboundslice(mosek.accmode.con,
    +                           2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b))
    +
    +        # setup variable bounds
    +        task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], 
    +                           (2*n+m)*[0.0], (2*n+m)*[0.0])
    +
    +        # optimize the task
    +        task.putobjsense(mosek.objsense.minimize)
    +        task.optimize()
    +        task.solutionsummary(mosek.streamtype.log)
    +        x = n*[0.0]
    +        task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)
    +
    +        return matrix(x)
    +
    +def l1regls(A, b):
    +    """
    +    
    +    Returns the solution of l1-norm regularized least-squares problem
    +  
    +        minimize || A*x - b ||_2^2  + || x ||_1.
    +
    +    """
    +
    +    m, n = A.size
    +    q = matrix(1.0, (2*n,1))
    +    q[:n] = -2.0 * A.T * b
    +
    +    def P(u, v, alpha = 1.0, beta = 0.0 ):
    +        """
    +            v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v 
    +        """
    +        v *= beta
    +        v[:n] += alpha * 2.0 * A.T * (A * u[:n])
    +
    +
    +    def G(u, v, alpha=1.0, beta=0.0, trans='N'):
    +        """
    +            v := alpha*[I, -I; -I, -I] * u + beta * v  (trans = 'N' or 'T')
    +        """
    +
    +        v *= beta
    +        v[:n] += alpha*(u[:n] - u[n:])
    +        v[n:] += alpha*(-u[:n] - u[n:])
    +
    +    h = matrix(0.0, (2*n,1))
    +
    +
    +    # Customized solver for the KKT system 
    +    #
    +    #     [  2.0*A'*A  0    I      -I     ] [x[:n] ]     [bx[:n] ]
    +    #     [  0         0   -I      -I     ] [x[n:] ]  =  [bx[n:] ].
    +    #     [  I        -I   -D1^-1   0     ] [zl[:n]]     [bzl[:n]]
    +    #     [ -I        -I    0      -D2^-1 ] [zl[n:]]     [bzl[n:]]
    +    #
    +    # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2.
    +    #    
    +    # We first eliminate zl and x[n:]:
    +    #
    +    #     ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = 
    +    #         bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +    #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +    #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:]           
    +    #
    +    #     x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +    #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +    #
    +    #     zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] )
    +    #     zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ).
    +    #
    +    # The first equation has the form
    +    #
    +    #     (A'*A + D)*x[:n]  =  rhs
    +    #
    +    # and is equivalent to
    +    #
    +    #     [ D    A' ] [ x:n] ]  = [ rhs ]
    +    #     [ A   -I  ] [ v    ]    [ 0   ].
    +    #
    +    # It can be solved as 
    +    #
    +    #     ( A*D^-1*A' + I ) * v = A * D^-1 * rhs
    +    #     x[:n] = D^-1 * ( rhs - A'*v ).
    +
    +    S = matrix(0.0, (m,m))
    +    Asc = matrix(0.0, (m,n))
    +    v = matrix(0.0, (m,1))
    +
    +    def Fkkt(W):
    +
    +        # Factor 
    +        #
    +        #     S = A*D^-1*A' + I 
    +        #
    +        # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2.
    +
    +        d1, d2 = W['di'][:n]**2, W['di'][n:]**2
    +
    +        # ds is square root of diagonal of D
    +        ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), 
    +            sqrt(d1+d2) )
    +        d3 =  div(d2 - d1, d1 + d2)
    +     
    +        # Asc = A*diag(d)^-1/2
    +        Asc = A * spdiag(ds**-1)
    +
    +        # S = I + A * D^-1 * A'
    +        blas.syrk(Asc, S)
    +        S[::m+1] += 1.0 
    +        lapack.potrf(S)
    +
    +        def g(x, y, z):
    +
    +            x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + 
    +                mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - 
    +                mul(d3, z[n:])) )
    +            x[:n] = div( x[:n], ds) 
    +
    +            # Solve
    +            #
    +            #     S * v = 0.5 * A * D^-1 * ( bx[:n] - 
    +            #         (D2-D1)*(D1+D2)^-1 * bx[n:] + 
    +            #         D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - 
    +            #         D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] )
    +                
    +            blas.gemv(Asc, x, v)
    +            lapack.potrs(S, v)
    +            
    +            # x[:n] = D^-1 * ( rhs - A'*v ).
    +            blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')
    +            x[:n] = div(x[:n], ds)
    +
    +            # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n]  - D2*bzl[n:] ) 
    +            #         - (D2-D1)*(D1+D2)^-1 * x[:n]         
    +            x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\
    +                - mul( d3, x[:n] )
    +                
    +            # zl[:n] = D1^1/2 * (  x[:n] - x[n:] - bzl[:n] )
    +            # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ).
    +            z[:n] = mul( W['di'][:n],  x[:n] - x[n:] - z[:n] ) 
    +            z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) 
    +
    +        return g
    +
    +    return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n]
    +
    +

    +









    +

    Friday September 10

    diff --git a/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz b/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz index de26ac7aa389e84ff1bac2713ea7ed60a3410a21..a59fb9041973f5cd6dd15c759880559cd56e7bcd 100644 GIT binary patch literal 191 zcmV;w06_mAiwFQLS3Y3?1MSbv3c@f92k@Qu6nTQt+IF4=ckm#H_yQe^uFkcy?a;lw z`v5&DUWN$$UH*iGknFS7dYdKw?xWcdLQ>9Q$YmwIZ6XyY+Arh*${#nMDIoz9^! t=!O1q(qL5B%B`#rW^vQ_EM&YlY@jTD-zV-md6cpS52mk=g%36{D diff --git a/doc/pub/week36/ipynb/week36.ipynb b/doc/pub/week36/ipynb/week36.ipynb index 000a9ec9c..96c70946b 100644 --- a/doc/pub/week36/ipynb/week36.ipynb +++ b/doc/pub/week36/ipynb/week36.ipynb @@ -10,7 +10,7 @@ " \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 10, 2021**\n", + "Date: **Sep 12, 2021**\n", "\n", "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", @@ -1476,6 +1476,298 @@ "plt.show()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using CVXOPT\n", + "\n", + "\n", + "As a small addendum, we note that you can also solve this problem\n", + "using the convex optimization package\n", + "[CVXOPT](https://cvxopt.org/examples/mlbook/l1regls.html). This\n", + "requires, in addition to having installed **CVXOPT**, you need to\n", + "download the file *l1regl.py*. The following code example solves the\n", + "simpler problem we discussed above, where we have added the latter\n", + "python file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from l1regls import l1regls\n", + "from cvxopt import matrix, normal\n", + "import numpy as np\n", + "\n", + "X = matrix( [ [ 2, 0, 1], [0, 1, 3]])\n", + "y = matrix( [4, 2, 3])\n", + "x = l1regls(X,y)\n", + "\n", + "from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed\n", + "from cvxopt import blas, lapack, solvers, sparse, spmatrix\n", + "import math\n", + "\n", + "try:\n", + " import mosek\n", + " import sys\n", + " __MOSEK = True\n", + "except: __MOSEK = False\n", + "\n", + "if __MOSEK:\n", + "\n", + " def l1regls_mosek(A, b):\n", + " \"\"\"\n", + "\n", + " Returns the solution of l1-norm regularized least-squares problem\n", + "\n", + " minimize || A*x - b ||_2^2 + e'*u\n", + "\n", + " subject to -u <= x <= u\n", + "\n", + " \"\"\"\n", + "\n", + " m, n = A.size\n", + "\n", + " env = mosek.Env()\n", + " task = env.Task(0,0)\n", + " task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))\n", + "\n", + " task.appendvars( 2*n) # number of variables\n", + " task.appendcons( 2*n) # number of constraints\n", + "\n", + " # input quadratic objective\n", + " Q = matrix(0.0, (n,n)) \n", + " blas.syrk(A, Q, alpha = 2.0, trans='T')\n", + "\n", + " I = []\n", + " for i in range(n):\n", + " I.extend(range(i,n))\n", + "\n", + " J = []\n", + " for i in range(n):\n", + " J.extend((n-i)*[i])\n", + "\n", + " task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n]))\n", + " task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0]) # setup linear objective\n", + "\n", + " # input constraint matrix row by row\n", + " for i in range(n):\n", + " task.putarow( i, [i, n+i], [1.0, -1.0])\n", + " task.putarow( n+i, [i, n+i], [1.0, 1.0])\n", + "\n", + " # setup bounds on constraints\n", + " task.putboundslice(mosek.accmode.con,\n", + " 0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])\n", + " task.putboundslice(mosek.accmode.con,\n", + " n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])\n", + "\n", + " # setup variable bounds\n", + " task.putboundslice(mosek.accmode.var,\n", + " 0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0])\n", + "\n", + " # optimize the task\n", + " task.putobjsense(mosek.objsense.minimize)\n", + " task.optimize()\n", + " task.solutionsummary(mosek.streamtype.log)\n", + " x = n*[0.0]\n", + " task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)\n", + "\n", + " return matrix(x)\n", + "\n", + " def l1regls_mosek2(A, b):\n", + " \"\"\"\n", + "\n", + " Returns the solution of l1-norm regularized least-squares problem\n", + "\n", + " minimize w'*w + e'*u\n", + "\n", + " subject to -u <= x <= u\n", + "\n", + " A*x - w = b\n", + "\n", + " \"\"\"\n", + "\n", + " m, n = A.size\n", + "\n", + " env = mosek.Env()\n", + " task = env.Task(0,0)\n", + " task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x))\n", + "\n", + " task.appendvars(2*n + m) # number of variables\n", + " task.appendcons(2*n + m) # number of constraints\n", + "\n", + " # input quadratic objective\n", + " task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0])\n", + "\n", + " task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0]) # setup linear objective\n", + "\n", + " # input constraint matrix row by row\n", + " for i in range(n):\n", + " task.putarow( i, [i, n+i], [1.0, -1.0])\n", + " task.putarow( n+i, [i, n+i], [1.0, 1.0])\n", + "\n", + " for i in range(m):\n", + " task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0])\n", + "\n", + " # setup bounds on constraints\n", + " task.putboundslice(mosek.accmode.con,\n", + " 0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0])\n", + " task.putboundslice(mosek.accmode.con,\n", + " n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0])\n", + " task.putboundslice(mosek.accmode.con,\n", + " 2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b))\n", + "\n", + " # setup variable bounds\n", + " task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], \n", + " (2*n+m)*[0.0], (2*n+m)*[0.0])\n", + "\n", + " # optimize the task\n", + " task.putobjsense(mosek.objsense.minimize)\n", + " task.optimize()\n", + " task.solutionsummary(mosek.streamtype.log)\n", + " x = n*[0.0]\n", + " task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x)\n", + "\n", + " return matrix(x)\n", + "\n", + "def l1regls(A, b):\n", + " \"\"\"\n", + " \n", + " Returns the solution of l1-norm regularized least-squares problem\n", + " \n", + " minimize || A*x - b ||_2^2 + || x ||_1.\n", + "\n", + " \"\"\"\n", + "\n", + " m, n = A.size\n", + " q = matrix(1.0, (2*n,1))\n", + " q[:n] = -2.0 * A.T * b\n", + "\n", + " def P(u, v, alpha = 1.0, beta = 0.0 ):\n", + " \"\"\"\n", + " v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v \n", + " \"\"\"\n", + " v *= beta\n", + " v[:n] += alpha * 2.0 * A.T * (A * u[:n])\n", + "\n", + "\n", + " def G(u, v, alpha=1.0, beta=0.0, trans='N'):\n", + " \"\"\"\n", + " v := alpha*[I, -I; -I, -I] * u + beta * v (trans = 'N' or 'T')\n", + " \"\"\"\n", + "\n", + " v *= beta\n", + " v[:n] += alpha*(u[:n] - u[n:])\n", + " v[n:] += alpha*(-u[:n] - u[n:])\n", + "\n", + " h = matrix(0.0, (2*n,1))\n", + "\n", + "\n", + " # Customized solver for the KKT system \n", + " #\n", + " # [ 2.0*A'*A 0 I -I ] [x[:n] ] [bx[:n] ]\n", + " # [ 0 0 -I -I ] [x[n:] ] = [bx[n:] ].\n", + " # [ I -I -D1^-1 0 ] [zl[:n]] [bzl[:n]]\n", + " # [ -I -I 0 -D2^-1 ] [zl[n:]] [bzl[n:]]\n", + " #\n", + " # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2.\n", + " # \n", + " # We first eliminate zl and x[n:]:\n", + " #\n", + " # ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = \n", + " # bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + \n", + " # D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - \n", + " # D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] \n", + " #\n", + " # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n] - D2*bzl[n:] ) \n", + " # - (D2-D1)*(D1+D2)^-1 * x[:n] \n", + " #\n", + " # zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] )\n", + " # zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ).\n", + " #\n", + " # The first equation has the form\n", + " #\n", + " # (A'*A + D)*x[:n] = rhs\n", + " #\n", + " # and is equivalent to\n", + " #\n", + " # [ D A' ] [ x:n] ] = [ rhs ]\n", + " # [ A -I ] [ v ] [ 0 ].\n", + " #\n", + " # It can be solved as \n", + " #\n", + " # ( A*D^-1*A' + I ) * v = A * D^-1 * rhs\n", + " # x[:n] = D^-1 * ( rhs - A'*v ).\n", + "\n", + " S = matrix(0.0, (m,m))\n", + " Asc = matrix(0.0, (m,n))\n", + " v = matrix(0.0, (m,1))\n", + "\n", + " def Fkkt(W):\n", + "\n", + " # Factor \n", + " #\n", + " # S = A*D^-1*A' + I \n", + " #\n", + " # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2.\n", + "\n", + " d1, d2 = W['di'][:n]**2, W['di'][n:]**2\n", + "\n", + " # ds is square root of diagonal of D\n", + " ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), \n", + " sqrt(d1+d2) )\n", + " d3 = div(d2 - d1, d1 + d2)\n", + " \n", + " # Asc = A*diag(d)^-1/2\n", + " Asc = A * spdiag(ds**-1)\n", + "\n", + " # S = I + A * D^-1 * A'\n", + " blas.syrk(Asc, S)\n", + " S[::m+1] += 1.0 \n", + " lapack.potrf(S)\n", + "\n", + " def g(x, y, z):\n", + "\n", + " x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + \n", + " mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - \n", + " mul(d3, z[n:])) )\n", + " x[:n] = div( x[:n], ds) \n", + "\n", + " # Solve\n", + " #\n", + " # S * v = 0.5 * A * D^-1 * ( bx[:n] - \n", + " # (D2-D1)*(D1+D2)^-1 * bx[n:] + \n", + " # D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - \n", + " # D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] )\n", + " \n", + " blas.gemv(Asc, x, v)\n", + " lapack.potrs(S, v)\n", + " \n", + " # x[:n] = D^-1 * ( rhs - A'*v ).\n", + " blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')\n", + " x[:n] = div(x[:n], ds)\n", + "\n", + " # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n] - D2*bzl[n:] ) \n", + " # - (D2-D1)*(D1+D2)^-1 * x[:n] \n", + " x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\\\n", + " - mul( d3, x[:n] )\n", + " \n", + " # zl[:n] = D1^1/2 * ( x[:n] - x[n:] - bzl[:n] )\n", + " # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ).\n", + " z[:n] = mul( W['di'][:n], x[:n] - x[n:] - z[:n] ) \n", + " z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) \n", + "\n", + " return g\n", + "\n", + " return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n]" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/doc/src/week36/week36.do.txt b/doc/src/week36/week36.do.txt index 7dcddbd68..5ac331223 100644 --- a/doc/src/week36/week36.do.txt +++ b/doc/src/week36/week36.do.txt @@ -897,6 +897,287 @@ plt.show() !ec +!split +===== Using CVXOPT ===== + + +As a small addendum, we note that you can also solve this problem +using the convex optimization package +"CVXOPT":"https://cvxopt.org/examples/mlbook/l1regls.html". This +requires, in addition to having installed _CVXOPT_, you need to +download the file *l1regl.py*. The following code example solves the +simpler problem we discussed above, where we have added the latter +python file. + +!bc pycod +from l1regls import l1regls +from cvxopt import matrix, normal +import numpy as np + +X = matrix( [ [ 2, 0, 1], [0, 1, 3]]) +y = matrix( [4, 2, 3]) +x = l1regls(X,y) + +from cvxopt import matrix, spdiag, mul, div, sqrt, normal, setseed +from cvxopt import blas, lapack, solvers, sparse, spmatrix +import math + +try: + import mosek + import sys + __MOSEK = True +except: __MOSEK = False + +if __MOSEK: + + def l1regls_mosek(A, b): + """ + + Returns the solution of l1-norm regularized least-squares problem + + minimize || A*x - b ||_2^2 + e'*u + + subject to -u <= x <= u + + """ + + m, n = A.size + + env = mosek.Env() + task = env.Task(0,0) + task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x)) + + task.appendvars( 2*n) # number of variables + task.appendcons( 2*n) # number of constraints + + # input quadratic objective + Q = matrix(0.0, (n,n)) + blas.syrk(A, Q, alpha = 2.0, trans='T') + + I = [] + for i in range(n): + I.extend(range(i,n)) + + J = [] + for i in range(n): + J.extend((n-i)*[i]) + + task.putqobj(I, J, list(Q[matrix(I) + matrix(J)*n])) + task.putclist(range(2*n), list(-2*A.T*b) + n*[1.0]) # setup linear objective + + # input constraint matrix row by row + for i in range(n): + task.putarow( i, [i, n+i], [1.0, -1.0]) + task.putarow( n+i, [i, n+i], [1.0, 1.0]) + + # setup bounds on constraints + task.putboundslice(mosek.accmode.con, + 0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0]) + task.putboundslice(mosek.accmode.con, + n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0]) + + # setup variable bounds + task.putboundslice(mosek.accmode.var, + 0, 2*n, 2*n*[mosek.boundkey.fr], 2*n*[0.0], 2*n*[0.0]) + + # optimize the task + task.putobjsense(mosek.objsense.minimize) + task.optimize() + task.solutionsummary(mosek.streamtype.log) + x = n*[0.0] + task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x) + + return matrix(x) + + def l1regls_mosek2(A, b): + """ + + Returns the solution of l1-norm regularized least-squares problem + + minimize w'*w + e'*u + + subject to -u <= x <= u + + A*x - w = b + + """ + + m, n = A.size + + env = mosek.Env() + task = env.Task(0,0) + task.set_Stream(mosek.streamtype.log, lambda x: sys.stdout.write(x)) + + task.appendvars(2*n + m) # number of variables + task.appendcons(2*n + m) # number of constraints + + # input quadratic objective + task.putqobj(range(2*n,2*n+m), range(2*n,2*n+m), m*[2.0]) + + task.putclist(range(2*n+m), n*[0.0] + n*[1.0] + m*[0.0]) # setup linear objective + + # input constraint matrix row by row + for i in range(n): + task.putarow( i, [i, n+i], [1.0, -1.0]) + task.putarow( n+i, [i, n+i], [1.0, 1.0]) + + for i in range(m): + task.putarow( 2*n+i, range(n) + [2*n+i], list(A[i,:]) + [-1.0]) + + # setup bounds on constraints + task.putboundslice(mosek.accmode.con, + 0, n, n*[mosek.boundkey.up], n*[0.0], n*[0.0]) + task.putboundslice(mosek.accmode.con, + n, 2*n, n*[mosek.boundkey.lo], n*[0.0], n*[0.0]) + task.putboundslice(mosek.accmode.con, + 2*n, 2*n+m, m*[mosek.boundkey.fx], list(b), list(b)) + + # setup variable bounds + task.putboundslice(mosek.accmode.var, 0, 2*n+m, (2*n+m)*[mosek.boundkey.fr], + (2*n+m)*[0.0], (2*n+m)*[0.0]) + + # optimize the task + task.putobjsense(mosek.objsense.minimize) + task.optimize() + task.solutionsummary(mosek.streamtype.log) + x = n*[0.0] + task.getsolutionslice(mosek.soltype.itr, mosek.solitem.xx, 0, n, x) + + return matrix(x) + +def l1regls(A, b): + """ + + Returns the solution of l1-norm regularized least-squares problem + + minimize || A*x - b ||_2^2 + || x ||_1. + + """ + + m, n = A.size + q = matrix(1.0, (2*n,1)) + q[:n] = -2.0 * A.T * b + + def P(u, v, alpha = 1.0, beta = 0.0 ): + """ + v := alpha * 2.0 * [ A'*A, 0; 0, 0 ] * u + beta * v + """ + v *= beta + v[:n] += alpha * 2.0 * A.T * (A * u[:n]) + + + def G(u, v, alpha=1.0, beta=0.0, trans='N'): + """ + v := alpha*[I, -I; -I, -I] * u + beta * v (trans = 'N' or 'T') + """ + + v *= beta + v[:n] += alpha*(u[:n] - u[n:]) + v[n:] += alpha*(-u[:n] - u[n:]) + + h = matrix(0.0, (2*n,1)) + + + # Customized solver for the KKT system + # + # [ 2.0*A'*A 0 I -I ] [x[:n] ] [bx[:n] ] + # [ 0 0 -I -I ] [x[n:] ] = [bx[n:] ]. + # [ I -I -D1^-1 0 ] [zl[:n]] [bzl[:n]] + # [ -I -I 0 -D2^-1 ] [zl[n:]] [bzl[n:]] + # + # where D1 = W['di'][:n]**2, D2 = W['di'][:n]**2. + # + # We first eliminate zl and x[n:]: + # + # ( 2*A'*A + 4*D1*D2*(D1+D2)^-1 ) * x[:n] = + # bx[:n] - (D2-D1)*(D1+D2)^-1 * bx[n:] + + # D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - + # D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] + # + # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n] - D2*bzl[n:] ) + # - (D2-D1)*(D1+D2)^-1 * x[:n] + # + # zl[:n] = D1 * ( x[:n] - x[n:] - bzl[:n] ) + # zl[n:] = D2 * (-x[:n] - x[n:] - bzl[n:] ). + # + # The first equation has the form + # + # (A'*A + D)*x[:n] = rhs + # + # and is equivalent to + # + # [ D A' ] [ x:n] ] = [ rhs ] + # [ A -I ] [ v ] [ 0 ]. + # + # It can be solved as + # + # ( A*D^-1*A' + I ) * v = A * D^-1 * rhs + # x[:n] = D^-1 * ( rhs - A'*v ). + + S = matrix(0.0, (m,m)) + Asc = matrix(0.0, (m,n)) + v = matrix(0.0, (m,1)) + + def Fkkt(W): + + # Factor + # + # S = A*D^-1*A' + I + # + # where D = 2*D1*D2*(D1+D2)^-1, D1 = d[:n]**-2, D2 = d[n:]**-2. + + d1, d2 = W['di'][:n]**2, W['di'][n:]**2 + + # ds is square root of diagonal of D + ds = math.sqrt(2.0) * div( mul( W['di'][:n], W['di'][n:]), + sqrt(d1+d2) ) + d3 = div(d2 - d1, d1 + d2) + + # Asc = A*diag(d)^-1/2 + Asc = A * spdiag(ds**-1) + + # S = I + A * D^-1 * A' + blas.syrk(Asc, S) + S[::m+1] += 1.0 + lapack.potrf(S) + + def g(x, y, z): + + x[:n] = 0.5 * ( x[:n] - mul(d3, x[n:]) + + mul(d1, z[:n] + mul(d3, z[:n])) - mul(d2, z[n:] - + mul(d3, z[n:])) ) + x[:n] = div( x[:n], ds) + + # Solve + # + # S * v = 0.5 * A * D^-1 * ( bx[:n] - + # (D2-D1)*(D1+D2)^-1 * bx[n:] + + # D1 * ( I + (D2-D1)*(D1+D2)^-1 ) * bzl[:n] - + # D2 * ( I - (D2-D1)*(D1+D2)^-1 ) * bzl[n:] ) + + blas.gemv(Asc, x, v) + lapack.potrs(S, v) + + # x[:n] = D^-1 * ( rhs - A'*v ). + blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T') + x[:n] = div(x[:n], ds) + + # x[n:] = (D1+D2)^-1 * ( bx[n:] - D1*bzl[:n] - D2*bzl[n:] ) + # - (D2-D1)*(D1+D2)^-1 * x[:n] + x[n:] = div( x[n:] - mul(d1, z[:n]) - mul(d2, z[n:]), d1+d2 )\ + - mul( d3, x[:n] ) + + # zl[:n] = D1^1/2 * ( x[:n] - x[n:] - bzl[:n] ) + # zl[n:] = D2^1/2 * ( -x[:n] - x[n:] - bzl[n:] ). + z[:n] = mul( W['di'][:n], x[:n] - x[n:] - z[:n] ) + z[n:] = mul( W['di'][n:], -x[:n] - x[n:] - z[n:] ) + + return g + + return solvers.coneqp(P, q, G, h, kktsolver = Fkkt)['x'][:n] + +!ec + !split ===== Friday September 10 =====