From 1e92fbd1093497cf270201d56df6d84c2dae8e84 Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Mon, 25 Aug 2025 07:39:58 +0200 Subject: [PATCH] update --- doc/pub/week35/html/._week35-bs000.html | 104 ++- doc/pub/week35/html/._week35-bs001.html | 104 ++- doc/pub/week35/html/._week35-bs002.html | 104 ++- doc/pub/week35/html/._week35-bs003.html | 104 ++- doc/pub/week35/html/._week35-bs004.html | 104 ++- doc/pub/week35/html/._week35-bs005.html | 106 ++- doc/pub/week35/html/._week35-bs006.html | 110 ++- doc/pub/week35/html/._week35-bs007.html | 104 ++- doc/pub/week35/html/._week35-bs008.html | 104 ++- doc/pub/week35/html/._week35-bs009.html | 104 ++- doc/pub/week35/html/._week35-bs010.html | 104 ++- doc/pub/week35/html/._week35-bs011.html | 104 ++- doc/pub/week35/html/._week35-bs012.html | 104 ++- doc/pub/week35/html/._week35-bs013.html | 104 ++- doc/pub/week35/html/._week35-bs014.html | 133 +-- doc/pub/week35/html/._week35-bs015.html | 141 ++-- doc/pub/week35/html/._week35-bs016.html | 133 ++- doc/pub/week35/html/._week35-bs017.html | 179 ++-- doc/pub/week35/html/._week35-bs018.html | 187 +++-- doc/pub/week35/html/._week35-bs019.html | 221 ++--- doc/pub/week35/html/._week35-bs020.html | 178 ++-- doc/pub/week35/html/._week35-bs021.html | 158 ++-- doc/pub/week35/html/._week35-bs022.html | 171 ++-- doc/pub/week35/html/._week35-bs023.html | 137 ++-- doc/pub/week35/html/._week35-bs024.html | 136 ++-- doc/pub/week35/html/._week35-bs025.html | 138 ++-- doc/pub/week35/html/._week35-bs026.html | 135 ++- doc/pub/week35/html/._week35-bs027.html | 163 ++-- doc/pub/week35/html/._week35-bs028.html | 163 ++-- doc/pub/week35/html/._week35-bs029.html | 205 +++-- doc/pub/week35/html/._week35-bs030.html | 227 ++---- doc/pub/week35/html/._week35-bs031.html | 135 ++- doc/pub/week35/html/._week35-bs032.html | 123 +-- doc/pub/week35/html/._week35-bs033.html | 156 ++-- doc/pub/week35/html/._week35-bs034.html | 181 ++-- doc/pub/week35/html/._week35-bs035.html | 157 ++-- doc/pub/week35/html/._week35-bs036.html | 162 ++-- doc/pub/week35/html/._week35-bs037.html | 264 ++++-- doc/pub/week35/html/._week35-bs038.html | 266 ++---- doc/pub/week35/html/._week35-bs039.html | 167 ++-- doc/pub/week35/html/._week35-bs040.html | 159 ++-- doc/pub/week35/html/._week35-bs041.html | 179 ++-- doc/pub/week35/html/._week35-bs042.html | 175 ++-- doc/pub/week35/html/._week35-bs043.html | 147 ++-- doc/pub/week35/html/._week35-bs044.html | 182 +++-- doc/pub/week35/html/._week35-bs045.html | 166 ++-- doc/pub/week35/html/._week35-bs046.html | 159 ++-- doc/pub/week35/html/._week35-bs047.html | 167 ++-- doc/pub/week35/html/._week35-bs048.html | 151 ++-- doc/pub/week35/html/._week35-bs049.html | 157 ++-- doc/pub/week35/html/._week35-bs050.html | 167 ++-- doc/pub/week35/html/._week35-bs051.html | 198 +++-- doc/pub/week35/html/._week35-bs052.html | 161 ++-- doc/pub/week35/html/._week35-bs053.html | 148 ++-- doc/pub/week35/html/._week35-bs054.html | 171 ++-- doc/pub/week35/html/._week35-bs055.html | 141 ++-- doc/pub/week35/html/._week35-bs056.html | 159 ++-- doc/pub/week35/html/._week35-bs057.html | 157 ++-- doc/pub/week35/html/._week35-bs058.html | 184 +++-- doc/pub/week35/html/._week35-bs059.html | 181 ++-- doc/pub/week35/html/._week35-bs060.html | 134 +-- doc/pub/week35/html/._week35-bs061.html | 135 ++- doc/pub/week35/html/week35-bs.html | 104 ++- doc/pub/week35/html/week35-reveal.html | 41 +- doc/pub/week35/html/week35-solarized.html | 35 +- doc/pub/week35/html/week35.html | 35 +- doc/pub/week35/ipynb/ipynb-week35-src.tar.gz | Bin 192 -> 192 bytes doc/pub/week35/ipynb/week35.ipynb | 816 +++++++++---------- doc/src/week35/week35.do.txt | 40 +- 69 files changed, 5119 insertions(+), 5410 deletions(-) diff --git a/doc/pub/week35/html/._week35-bs000.html b/doc/pub/week35/html/._week35-bs000.html index badf47a47..028edad4c 100644 --- a/doc/pub/week35/html/._week35-bs000.html +++ b/doc/pub/week35/html/._week35-bs000.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -361,7 +359,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs001.html b/doc/pub/week35/html/._week35-bs001.html index a3d94ee4e..b29e8344f 100644 --- a/doc/pub/week35/html/._week35-bs001.html +++ b/doc/pub/week35/html/._week35-bs001.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -358,7 +356,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs002.html b/doc/pub/week35/html/._week35-bs002.html index e28b1e21c..1bb1245b2 100644 --- a/doc/pub/week35/html/._week35-bs002.html +++ b/doc/pub/week35/html/._week35-bs002.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -357,7 +355,7 @@ Similarly, Mehta et al
  • 11
  • 12
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs003.html b/doc/pub/week35/html/._week35-bs003.html index 08298ae07..1a2bcf6bc 100644 --- a/doc/pub/week35/html/._week35-bs003.html +++ b/doc/pub/week35/html/._week35-bs003.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -382,7 +380,7 @@ values \( \tilde{y}_i \), namely the so-called cost/loss function.
  • 12
  • 13
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs004.html b/doc/pub/week35/html/._week35-bs004.html index 56f67c9f2..0e606ba5d 100644 --- a/doc/pub/week35/html/._week35-bs004.html +++ b/doc/pub/week35/html/._week35-bs004.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -364,7 +362,7 @@ $$
  • 13
  • 14
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs005.html b/doc/pub/week35/html/._week35-bs005.html index eced6e858..6d5c26e46 100644 --- a/doc/pub/week35/html/._week35-bs005.html +++ b/doc/pub/week35/html/._week35-bs005.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -347,7 +345,7 @@ will treat \( y_i \) as our exact value for the output variable.

    In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem

    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in +\hat{\boldsymbol{\theta}}={\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$ @@ -387,7 +385,7 @@ $$
  • 14
  • 15
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs006.html b/doc/pub/week35/html/._week35-bs006.html index ae33a7f1f..ddc19a43a 100644 --- a/doc/pub/week35/html/._week35-bs006.html +++ b/doc/pub/week35/html/._week35-bs006.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -337,7 +335,7 @@ $$

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ -\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +\hat{\boldsymbol{\theta}} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in @@ -348,7 +346,7 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). This is discussed on Thursday this week. +\( \boldsymbol{X}^T\boldsymbol{X} \).

    @@ -357,7 +355,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi
    -

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    +

    Small question: When inverting the matrix $\boldsymbol{X}^T\boldsymbol{X}, what kind of problems can we expect?

    @@ -383,7 +381,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi
  • 15
  • 16
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs007.html b/doc/pub/week35/html/._week35-bs007.html index 574ade213..fa29b1fd7 100644 --- a/doc/pub/week35/html/._week35-bs007.html +++ b/doc/pub/week35/html/._week35-bs007.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -370,7 +368,7 @@ $$
  • 16
  • 17
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs008.html b/doc/pub/week35/html/._week35-bs008.html index 4bb182a05..f646e30f9 100644 --- a/doc/pub/week35/html/._week35-bs008.html +++ b/doc/pub/week35/html/._week35-bs008.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -368,7 +366,7 @@ vector is differentiable.
  • 17
  • 18
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs009.html b/doc/pub/week35/html/._week35-bs009.html index fa2816cb9..1a682b3b9 100644 --- a/doc/pub/week35/html/._week35-bs009.html +++ b/doc/pub/week35/html/._week35-bs009.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -367,7 +365,7 @@ $$
  • 18
  • 19
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs010.html b/doc/pub/week35/html/._week35-bs010.html index e149a2b82..5907bd1ef 100644 --- a/doc/pub/week35/html/._week35-bs010.html +++ b/doc/pub/week35/html/._week35-bs010.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -378,7 +376,7 @@ $$
  • 19
  • 20
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs011.html b/doc/pub/week35/html/._week35-bs011.html index 9175c34f7..17b5510cf 100644 --- a/doc/pub/week35/html/._week35-bs011.html +++ b/doc/pub/week35/html/._week35-bs011.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -380,7 +378,7 @@ $$
  • 20
  • 21
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs012.html b/doc/pub/week35/html/._week35-bs012.html index 629685f49..a9ab18ebf 100644 --- a/doc/pub/week35/html/._week35-bs012.html +++ b/doc/pub/week35/html/._week35-bs012.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -381,7 +379,7 @@ $$
  • 21
  • 22
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs013.html b/doc/pub/week35/html/._week35-bs013.html index 1e506fa7c..341b965f5 100644 --- a/doc/pub/week35/html/._week35-bs013.html +++ b/doc/pub/week35/html/._week35-bs013.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -393,7 +391,7 @@ $$
  • 22
  • 23
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs014.html b/doc/pub/week35/html/._week35-bs014.html index 62b194ea7..eef1a405d 100644 --- a/doc/pub/week35/html/._week35-bs014.html +++ b/doc/pub/week35/html/._week35-bs014.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,26 +319,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Other useful relations

    +

    Meet the Hessian Matrix

    -

    We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters)

    -$$ -\frac{\partial (\boldsymbol{x}^T\boldsymbol{a})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ +

    A very important matrix we will meet again and again in machine +learning is the Hessian. It is given by the second derivative of the +cost function with respect to the parameters \( \boldsymbol{\theta} \). Using the above +expression for derivatives of vectors and matrices, we find that the +second derivative of the mean squared error as cost function is, +

    $$ -\frac{\partial (\boldsymbol{a}^T\boldsymbol{x})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, +\frac{\partial}{\partial \boldsymbol{\theta}}\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}^T} =\frac{\partial}{\partial \boldsymbol{\theta}}\left[-\frac{2}{n}\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right]=\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. $$ +

    The Hessian matrix plays an important role and is defined here as

    $$ -\frac{\partial tr(\boldsymbol{B}\boldsymbol{A})}{\partial \boldsymbol{A}} = \boldsymbol{B}^T, +\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. $$ -$$ -\frac{\partial \log{\vert\boldsymbol{A}\vert}}{\partial \boldsymbol{A}} = (\boldsymbol{A}^{-1})^T. -$$ +

    For ordinary least squares, it is inversely proportional (derivation +next week) with the variance of the optimal parameters +\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see next week that it is +(aside the factor \( 1/n \)) equal to the covariance matrix. It plays also a very +important role in optmization algorithms and Principal Component +Analysis as a way to reduce the dimensionality of a machine learning/data analysis +problem. We will discuss this in greater detail next week when we introduce gradient methods. +

    +

    Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).

    @@ -367,7 +374,7 @@ $$

  • 23
  • 24
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs015.html b/doc/pub/week35/html/._week35-bs015.html index 09202c70b..3287b99ca 100644 --- a/doc/pub/week35/html/._week35-bs015.html +++ b/doc/pub/week35/html/._week35-bs015.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,35 +319,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Meet the Hessian Matrix

    - -

    A very important matrix we will meet again and again in machine -learning is the Hessian. It is given by the second derivative of the -cost function with respect to the parameters \( \boldsymbol{\theta} \). Using the above -expression for derivatives of vectors and matrices, we find that the -second derivative of the mean squared error as cost function is, -

    +

    Interpretations and optimizing our parameters

    +
    +
    + +

    The residuals \( \boldsymbol{\epsilon} \) are in turn given by

    $$ -\frac{\partial}{\partial \boldsymbol{\theta}}\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}^T} =\frac{\partial}{\partial \boldsymbol{\theta}}\left[-\frac{2}{n}\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right]=\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}, $$ -

    The Hessian matrix plays an important role and is defined here as

    - +

    and with

    $$ -\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0, $$ -

    For ordinary least squares, it is inversely proportional (derivation -next week) with the variance of the optimal parameters -\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see later this week that it is -(aside the factor \( 1/n \)) equal to the covariance matrix. It plays also a very -important role in optmization algorithms and Principal Component -Analysis as a way to reduce the dimensionality of a machine learning/data analysis -problem. -

    +

    we have

    +$$ +\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0, +$$ + +

    meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals.

    +
    +
    -

    Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).

    @@ -376,7 +369,7 @@ problem.

  • 24
  • 25
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs016.html b/doc/pub/week35/html/._week35-bs016.html index f6135cabb..8a910a263 100644 --- a/doc/pub/week35/html/._week35-bs016.html +++ b/doc/pub/week35/html/._week35-bs016.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,30 +319,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Interpretations and optimizing our parameters

    +

    Example relevant for the exercises

    -
    -
    - -

    The residuals \( \boldsymbol{\epsilon} \) are in turn given by

    +

    In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), +we condiser a simple polynomial fit. +We assume our data can represented by a fourth-order polynomial. For the $i$th component we have +

    $$ -\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}, +\tilde{y}_i = \theta_0+\theta_1x_i+\theta_2x_i^2+\theta_3x_i^3+\theta_4x_i^4. $$ -

    and with

    -$$ -\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0, -$$ - -

    we have

    -$$ -\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0, -$$ - -

    meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals.

    -
    -
    - +

    we have five predictors/features. The first is the intercept \( \theta_0 \). The other terms are \( \theta_i \) with \( i=1,2,3,4 \). Furthermore we have \( n \) entries for each predictor. It means that our design matrix is an +\( n\times p \) matrix \( \boldsymbol{X} \). +

    @@ -371,7 +358,7 @@ $$

  • 25
  • 26
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs017.html b/doc/pub/week35/html/._week35-bs017.html index 51dbd8e8d..148f1002d 100644 --- a/doc/pub/week35/html/._week35-bs017.html +++ b/doc/pub/week35/html/._week35-bs017.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,19 +319,72 @@ MathJax.Hub.Config({

     

     

     

    -

    Example relevant for the exercises

    +

    Own code for Ordinary Least Squares

    -

    In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), -we condiser a simple polynomial fit. -We assume our data can represented by a fourth-order polynomial. For the $i$th component we have -

    -$$ -\tilde{y}_i = \theta_0+\theta_1x_i+\theta_2x_i^2+\theta_3x_i^3+\theta_4x_i^4. -$$ +

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) and the outputs \( \boldsymbol{y} \) we have

    + + +
    +
    +
    +
    +
    +
    # matrix inversion to find theta
    +# First we set up the data
    +import numpy as np
    +x = np.random.rand(100)
    +y = 2.0+5*x*x+0.1*np.random.randn(100)
    +# and then the design matrix X including the intercept
    +#  The design matrix now as function of a fourth-order polynomial
    +X = np.zeros((len(x),5))
    +X[:,0] = 1.0
    +X[:,1] = x
    +X[:,2] = x**2
    +X[:,3] = x**3
    +X[:,4] = x**4
    +theta = (np.linalg.inv(X.T @ X) @ X.T ) @ y
    +# and then make the prediction
    +ytilde = X @ theta
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Alternatively, you can use the least squares functionality in Numpy as

    + + +
    +
    +
    +
    +
    +
    fit = np.linalg.lstsq(X, y, rcond =None)[0]
    +ytildenp = np.dot(fit,X.T)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    we have five predictors/features. The first is the intercept \( \theta_0 \). The other terms are \( \theta_i \) with \( i=1,2,3,4 \). Furthermore we have \( n \) entries for each predictor. It means that our design matrix is an -\( n\times p \) matrix \( \boldsymbol{X} \). -

    @@ -360,7 +411,7 @@ $$

  • 26
  • 27
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs018.html b/doc/pub/week35/html/._week35-bs018.html index 438d297e9..1c4a55cf9 100644 --- a/doc/pub/week35/html/._week35-bs018.html +++ b/doc/pub/week35/html/._week35-bs018.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,9 +319,11 @@ MathJax.Hub.Config({

     

     

     

    -

    Own code for Ordinary Least Squares

    +

    Adding error analysis and training set up

    -

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) and the outputs \( \boldsymbol{y} \) we have

    +

    We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. +Since we are not using Scikit-Learn here we can define our own \( R2 \) function as +

    @@ -331,22 +331,8 @@ MathJax.Hub.Config({
    -
    # matrix inversion to find theta
    -# First we set up the data
    -import numpy as np
    -x = np.random.rand(100)
    -y = 2.0+5*x*x+0.1*np.random.randn(100)
    -# and then the design matrix X including the intercept
    -#  The design matrix now as function of a fourth-order polynomial
    -X = np.zeros((len(x),5))
    -X[:,0] = 1.0
    -X[:,1] = x
    -X[:,2] = x**2
    -X[:,3] = x**3
    -X[:,4] = x**4
    -theta = (np.linalg.inv(X.T @ X) @ X.T ) @ y
    -# and then make the prediction
    -ytilde = X @ theta
    +  
    def R2(y_data, y_model):
    +    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
     
    @@ -362,7 +348,7 @@ ytilde = X @
    -

    Alternatively, you can use the least squares functionality in Numpy as

    +

    and we would be using it as

    @@ -370,8 +356,61 @@ ytilde = X @
    -
    fit = np.linalg.lstsq(X, y, rcond =None)[0]
    -ytildenp = np.dot(fit,X.T)
    +  
    print(R2(y,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can easily add our MSE score as

    + + +
    +
    +
    +
    +
    +
    def MSE(y_data,y_model):
    +    n = np.size(y_model)
    +    return np.sum((y_data-y_model)**2)/n
    +
    +print(MSE(y,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    and finally the relative error as

    + + +
    +
    +
    +
    +
    +
    def RelativeError(y_data,y_model):
    +    return abs((y_data-y_model)/y_data)
    +print(RelativeError(y, ytilde))
     
    @@ -413,7 +452,7 @@ ytildenp = np.<
  • 27
  • 28
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs019.html b/doc/pub/week35/html/._week35-bs019.html index 8489d2b69..dc5296e60 100644 --- a/doc/pub/week35/html/._week35-bs019.html +++ b/doc/pub/week35/html/._week35-bs019.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,111 +319,24 @@ MathJax.Hub.Config({

     

     

     

    -

    Adding error analysis and training set up

    +

    Splitting our Data in Training and Test data

    -

    We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. -Since we are not using Scikit-Learn here we can define our own \( R2 \) function as +

    +
    + + +

    It is normal in essentially all Machine Learning studies to split the +data in a training set and a test set (sometimes also an additional +validation set). Scikit-Learn has an own function for this. There +is no explicit recipe for how much data should be included as training +data and say test data. An accepted rule of thumb is to use +approximately \( 2/3 \) to \( 4/5 \) of the data as training data. We will +postpone a discussion of this splitting to the end of these notes and +our discussion of the so-called bias-variance tradeoff. Here we +limit ourselves to repeat the above equation of state fitting example +but now splitting the data into a training set and a test set.

    - - -
    -
    -
    -
    -
    -
    def R2(y_data, y_model):
    -    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    and we would be using it as

    - - -
    -
    -
    -
    -
    -
    print(R2(y,ytilde))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    We can easily add our MSE score as

    - - -
    -
    -
    -
    -
    -
    def MSE(y_data,y_model):
    -    n = np.size(y_model)
    -    return np.sum((y_data-y_model)**2)/n
    -
    -print(MSE(y,ytilde))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    and finally the relative error as

    - - -
    -
    -
    -
    -
    -
    def RelativeError(y_data,y_model):
    -    return abs((y_data-y_model)/y_data)
    -print(RelativeError(y, ytilde))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    @@ -454,7 +365,7 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
  • 28
  • 29
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs020.html b/doc/pub/week35/html/._week35-bs020.html index 8f45ebe85..ab71f10d5 100644 --- a/doc/pub/week35/html/._week35-bs020.html +++ b/doc/pub/week35/html/._week35-bs020.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,24 +319,68 @@ MathJax.Hub.Config({

     

     

     

    -

    Splitting our Data in Training and Test data

    +

    The complete code with a simple data set

    -
    -
    - -

    It is normal in essentially all Machine Learning studies to split the -data in a training set and a test set (sometimes also an additional -validation set). Scikit-Learn has an own function for this. There -is no explicit recipe for how much data should be included as training -data and say test data. An accepted rule of thumb is to use -approximately \( 2/3 \) to \( 4/5 \) of the data as training data. We will -postpone a discussion of this splitting to the end of these notes and -our discussion of the so-called bias-variance tradeoff. Here we -limit ourselves to repeat the above equation of state fitting example -but now splitting the data into a training set and a test set. -

    + +
    +
    +
    +
    +
    +
    import os
    +import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +
    +
    +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
    +
    +x = np.random.rand(100)
    +y = 2.0+5*x*x+0.1*np.random.randn(100)
    +
    +
    +#  The design matrix now as function of a fourth-order polynomial
    +X = np.zeros((len(x),5))
    +X[:,0] = 1.0
    +X[:,1] = x
    +X[:,2] = x**2
    +X[:,3] = x**3
    +X[:,4] = x**4
    +# 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 theta
    +theta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    +print(theta)
    +# and then make the prediction
    +ytilde = X_train @ theta
    +print("Training R2")
    +print(R2(y_train,ytilde))
    +print("Training MSE")
    +print(MSE(y_train,ytilde))
    +ypredict = X_test @ theta
    +print("Test R2")
    +print(R2(y_test,ypredict))
    +print("Test MSE")
    +print(MSE(y_test,ypredict))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    @@ -367,7 +409,7 @@ but now splitting the data into a training set and a test set.
  • 29
  • 30
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs021.html b/doc/pub/week35/html/._week35-bs021.html index 77d7a2ea4..8b3117821 100644 --- a/doc/pub/week35/html/._week35-bs021.html +++ b/doc/pub/week35/html/._week35-bs021.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,7 +319,7 @@ MathJax.Hub.Config({

     

     

     

    -

    The complete code with a simple data set

    +

    Making your own test-train splitting

    @@ -330,46 +328,20 @@ MathJax.Hub.Config({
    -
    import os
    -import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    +  
    # equivalently in numpy
    +def train_test_split_numpy(inputs, labels, train_size, test_size):
    +    n_inputs = len(inputs)
    +    inputs_shuffled = inputs.copy()
    +    labels_shuffled = labels.copy()
     
    +    np.random.shuffle(inputs_shuffled)
    +    np.random.shuffle(labels_shuffled)
     
    -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
    +    train_end = int(n_inputs*train_size)
    +    X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]
    +    Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]
     
    -x = np.random.rand(100)
    -y = 2.0+5*x*x+0.1*np.random.randn(100)
    -
    -
    -#  The design matrix now as function of a fourth-order polynomial
    -X = np.zeros((len(x),5))
    -X[:,0] = 1.0
    -X[:,1] = x
    -X[:,2] = x**2
    -X[:,3] = x**3
    -X[:,4] = x**4
    -# 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 theta
    -theta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    -print(theta)
    -# and then make the prediction
    -ytilde = X_train @ theta
    -print("Training R2")
    -print(R2(y_train,ytilde))
    -print("Training MSE")
    -print(MSE(y_train,ytilde))
    -ypredict = X_test @ theta
    -print("Test R2")
    -print(R2(y_test,ypredict))
    -print("Test MSE")
    -print(MSE(y_test,ypredict))
    +    return X_train, X_test, Y_train, Y_test
     
    @@ -385,6 +357,10 @@ ypredict = X_test = X_test 30
  • 31
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs022.html b/doc/pub/week35/html/._week35-bs022.html index 5eb1abad4..29628a345 100644 --- a/doc/pub/week35/html/._week35-bs022.html +++ b/doc/pub/week35/html/._week35-bs022.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,49 +319,36 @@ MathJax.Hub.Config({

     

     

     

    -

    Making your own test-train splitting

    +

    Reducing the number of degrees of freedom, overarching view

    +
    +
    + - - -
    -
    -
    -
    -
    -
    # equivalently in numpy
    -def train_test_split_numpy(inputs, labels, train_size, test_size):
    -    n_inputs = len(inputs)
    -    inputs_shuffled = inputs.copy()
    -    labels_shuffled = labels.copy()
    -
    -    np.random.shuffle(inputs_shuffled)
    -    np.random.shuffle(labels_shuffled)
    -
    -    train_end = int(n_inputs*train_size)
    -    X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]
    -    Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]
    -
    -    return X_train, X_test, Y_train, Y_test
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    But since scikit-learn has its own function for doing this and since -it interfaces easily with tensorflow and other libraries, we -normally recommend using the latter functionality. +

    Many Machine Learning problems involve thousands or even millions of +features for each training instance. Not only does this make training +extremely slow, it can also make it much harder to find a good +solution, as we will see. This problem is often referred to as the +curse of dimensionality. Fortunately, in real-world problems, it is +often possible to reduce the number of features considerably, turning +an intractable problem into a tractable one.

    +

    Later we will discuss some of the most popular dimensionality reduction +techniques: the principal component analysis (PCA), Kernel PCA, and +Locally Linear Embedding (LLE). +

    + +

    Principal component analysis and its various variants deal with the +problem of fitting a low-dimensional affine +subspace to a set of of +data points in a high-dimensional space. With its family of methods it +is one of the most used tools in data modeling, compression and +visualization. +

    +
    +
    + +

      @@ -389,7 +374,7 @@ normally recommend using the latter functionality.
    • 31
    • 32
    • ...
    • -
    • 63
    • +
    • 62
    • »
    diff --git a/doc/pub/week35/html/._week35-bs023.html b/doc/pub/week35/html/._week35-bs023.html index 8f61a5167..02fa39390 100644 --- a/doc/pub/week35/html/._week35-bs023.html +++ b/doc/pub/week35/html/._week35-bs023.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,31 +319,26 @@ MathJax.Hub.Config({

     

     

     

    -

    Reducing the number of degrees of freedom, overarching view

    +

    Preprocessing our data

    -

    Many Machine Learning problems involve thousands or even millions of -features for each training instance. Not only does this make training -extremely slow, it can also make it much harder to find a good -solution, as we will see. This problem is often referred to as the -curse of dimensionality. Fortunately, in real-world problems, it is -often possible to reduce the number of features considerably, turning -an intractable problem into a tractable one. +

    Before we proceed however, we will discuss how to preprocess our +data. Till now and in connection with our previous examples we have +not met so many cases where we are too sensitive to the scaling of our +data. Normally the data may need a rescaling and/or may be sensitive +to extreme values. Scaling the data renders our inputs much more +suitable for the algorithms we want to employ.

    -

    Later we will discuss some of the most popular dimensionality reduction -techniques: the principal component analysis (PCA), Kernel PCA, and -Locally Linear Embedding (LLE). -

    - -

    Principal component analysis and its various variants deal with the -problem of fitting a low-dimensional affine -subspace to a set of of -data points in a high-dimensional space. With its family of methods it -is one of the most used tools in data modeling, compression and -visualization. +

    For data sets gathered for real world applications, it is rather normal that +different features have very different units and +numerical scales. For example, a data set detailing health habits may include +features such as age in the range \( 0-80 \), and caloric intake of order \( 2000 \). +Many machine learning methods sensitive to the scales of the features and may perform poorly if they +are very different scales. Therefore, it is typical to scale +the features in a way to avoid such outlier values.

    @@ -376,7 +369,7 @@ visualization.
  • 32
  • 33
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs024.html b/doc/pub/week35/html/._week35-bs024.html index e1a9b275b..a6e7d3b19 100644 --- a/doc/pub/week35/html/._week35-bs024.html +++ b/doc/pub/week35/html/._week35-bs024.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,31 +319,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Preprocessing our data

    -
    -
    - +

    Functionality in Scikit-Learn

    -

    Before we proceed however, we will discuss how to preprocess our -data. Till now and in connection with our previous examples we have -not met so many cases where we are too sensitive to the scaling of our -data. Normally the data may need a rescaling and/or may be sensitive -to extreme values. Scaling the data renders our inputs much more -suitable for the algorithms we want to employ. +

    Scikit-Learn has several functions which allow us to rescale the +data, normally resulting in much better results in terms of various +accuracy scores. The StandardScaler function in Scikit-Learn +ensures that for each feature/predictor we study the mean value is +zero and the variance is one (every column in the design/feature +matrix). This scaling has the drawback that it does not ensure that +we have a particular maximum or minimum in our data set. Another +function included in Scikit-Learn is the MinMaxScaler which +ensures that all features are exactly between \( 0 \) and \( 1 \). The

    -

    For data sets gathered for real world applications, it is rather normal that -different features have very different units and -numerical scales. For example, a data set detailing health habits may include -features such as age in the range \( 0-80 \), and caloric intake of order \( 2000 \). -Many machine learning methods sensitive to the scales of the features and may perform poorly if they -are very different scales. Therefore, it is typical to scale -the features in a way to avoid such outlier values. -

    -
    -
    - -

      @@ -371,7 +357,7 @@ the features in a way to avoid such outlier values.
    • 33
    • 34
    • ...
    • -
    • 63
    • +
    • 62
    • »
    diff --git a/doc/pub/week35/html/._week35-bs025.html b/doc/pub/week35/html/._week35-bs025.html index 92f12a6a3..25ff389f5 100644 --- a/doc/pub/week35/html/._week35-bs025.html +++ b/doc/pub/week35/html/._week35-bs025.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,19 +319,33 @@ MathJax.Hub.Config({

     

     

     

    -

    Functionality in Scikit-Learn

    +

    More preprocessing

    -

    Scikit-Learn has several functions which allow us to rescale the -data, normally resulting in much better results in terms of various -accuracy scores. The StandardScaler function in Scikit-Learn -ensures that for each feature/predictor we study the mean value is -zero and the variance is one (every column in the design/feature -matrix). This scaling has the drawback that it does not ensure that -we have a particular maximum or minimum in our data set. Another -function included in Scikit-Learn is the MinMaxScaler which -ensures that all features are exactly between \( 0 \) and \( 1 \). The +

    +
    + +

    The Normalizer scales each data +point such that the feature vector has a euclidean length of one. In other words, it +projects a data point on the circle (or sphere in the case of higher dimensions) with a +radius of 1. This means every data point is scaled by a different number (by the +inverse of it’s length). +This normalization is often used when only the direction (or angle) of the data matters, +not the length of the feature vector.

    +

    The RobustScaler works similarly to the StandardScaler in that it +ensures statistical properties for each feature that guarantee that +they are on the same scale. However, the RobustScaler uses the median +and quartiles, instead of mean and variance. This makes the +RobustScaler ignore data points that are very different from the rest +(like measurement errors). These odd data points are also called +outliers, and might often lead to trouble for other scaling +techniques. +

    +
    +
    + +

      @@ -359,7 +371,7 @@ ensures that all features are exactly between \( 0 \) and \( 1 \). The
    • 34
    • 35
    • ...
    • -
    • 63
    • +
    • 62
    • »
    diff --git a/doc/pub/week35/html/._week35-bs026.html b/doc/pub/week35/html/._week35-bs026.html index 74a8d7ce6..3f1ab1c3f 100644 --- a/doc/pub/week35/html/._week35-bs026.html +++ b/doc/pub/week35/html/._week35-bs026.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,32 +319,19 @@ MathJax.Hub.Config({

     

     

     

    -

    More preprocessing

    +

    Frequently used scaling functions

    -
    -
    - -

    The Normalizer scales each data -point such that the feature vector has a euclidean length of one. In other words, it -projects a data point on the circle (or sphere in the case of higher dimensions) with a -radius of 1. This means every data point is scaled by a different number (by the -inverse of it’s length). -This normalization is often used when only the direction (or angle) of the data matters, -not the length of the feature vector. +

    Many features are often scaled using standardization to improve performance. In Scikit-Learn this is given by the StandardScaler function as discussed above. It is easy however to write your own. +Mathematically, this involves subtracting the mean and divide by the standard deviation over the data set, for each feature:

    -

    The RobustScaler works similarly to the StandardScaler in that it -ensures statistical properties for each feature that guarantee that -they are on the same scale. However, the RobustScaler uses the median -and quartiles, instead of mean and variance. This makes the -RobustScaler ignore data points that are very different from the rest -(like measurement errors). These odd data points are also called -outliers, and might often lead to trouble for other scaling -techniques. -

    -
    -
    +$$ + x_j^{(i)} \rightarrow \frac{x_j^{(i)} - \overline{x}_j}{\sigma(x_j)}, +$$ +

    where \( \overline{x}_j \) and \( \sigma(x_j) \) are the mean and standard deviation, respectively, of the feature \( x_j \). +This ensures that each feature has zero mean and unit standard deviation. For data sets where we do not have the standard deviation or don't wish to calculate it, it is then common to simply set it to one. +

    @@ -373,7 +358,7 @@ techniques.

  • 35
  • 36
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs027.html b/doc/pub/week35/html/._week35-bs027.html index a14d2cd4d..71fcaad39 100644 --- a/doc/pub/week35/html/._week35-bs027.html +++ b/doc/pub/week35/html/._week35-bs027.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,19 +319,60 @@ MathJax.Hub.Config({

     

     

     

    -

    Frequently used scaling functions

    +

    Example of own Standard scaling

    -

    Many features are often scaled using standardization to improve performance. In Scikit-Learn this is given by the StandardScaler function as discussed above. It is easy however to write your own. -Mathematically, this involves subtracting the mean and divide by the standard deviation over the data set, for each feature: +

    Let us consider the following vanilla example where we use both +Scikit-Learn and write our own function as well. We produce a +simple test design matrix with random numbers. Each column could then +represent a specific feature whose mean value is subracted.

    -$$ - x_j^{(i)} \rightarrow \frac{x_j^{(i)} - \overline{x}_j}{\sigma(x_j)}, -$$ -

    where \( \overline{x}_j \) and \( \sigma(x_j) \) are the mean and standard deviation, respectively, of the feature \( x_j \). -This ensures that each feature has zero mean and unit standard deviation. For data sets where we do not have the standard deviation or don't wish to calculate it, it is then common to simply set it to one. -

    + +
    +
    +
    +
    +
    +
    import sklearn.linear_model as skl
    +from sklearn.metrics import mean_squared_error
    +from sklearn.model_selection import  train_test_split
    +from sklearn.preprocessing import MinMaxScaler, StandardScaler, Normalizer
    +import numpy as np
    +import pandas as pd
    +from IPython.display import display
    +np.random.seed(100)
    +# setting up a 10 x 5 matrix
    +rows = 10
    +cols = 5
    +X = np.random.randn(rows,cols)
    +XPandas = pd.DataFrame(X)
    +display(XPandas)
    +print(XPandas.mean())
    +print(XPandas.std())
    +XPandas = (XPandas -XPandas.mean())
    +display(XPandas)
    +#  This option does not include the standard deviation
    +scaler = StandardScaler(with_std=False)
    +scaler.fit(X)
    +Xscaled = scaler.transform(X)
    +display(XPandas-Xscaled)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Small exercise: perform the standard scaling by including the standard deviation and compare with what Scikit-Learn gives.

    @@ -360,7 +399,7 @@ This ensures that each feature has zero mean and unit standard deviation. For d

  • 36
  • 37
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs028.html b/doc/pub/week35/html/._week35-bs028.html index f83ed32fe..1c6aedfce 100644 --- a/doc/pub/week35/html/._week35-bs028.html +++ b/doc/pub/week35/html/._week35-bs028.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,60 +319,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Example of own Standard scaling

    +

    Min-Max Scaling

    -

    Let us consider the following vanilla example where we use both -Scikit-Learn and write our own function as well. We produce a -simple test design matrix with random numbers. Each column could then -represent a specific feature whose mean value is subracted. +

    Another commonly used scaling method is min-max scaling. This is very +useful for when we want the features to lie in a certain interval. To +scale the feature \( x_j \) to the interval \( [a, b] \), we can apply the +transformation

    +$$ +x_j^{(i)} \rightarrow (b-a)\frac{x_j^{(i)} - \min(x_j)}{\max(x_j) - \min(x_j)} - a +$$ - -
    -
    -
    -
    -
    -
    import sklearn.linear_model as skl
    -from sklearn.metrics import mean_squared_error
    -from sklearn.model_selection import  train_test_split
    -from sklearn.preprocessing import MinMaxScaler, StandardScaler, Normalizer
    -import numpy as np
    -import pandas as pd
    -from IPython.display import display
    -np.random.seed(100)
    -# setting up a 10 x 5 matrix
    -rows = 10
    -cols = 5
    -X = np.random.randn(rows,cols)
    -XPandas = pd.DataFrame(X)
    -display(XPandas)
    -print(XPandas.mean())
    -print(XPandas.std())
    -XPandas = (XPandas -XPandas.mean())
    -display(XPandas)
    -#  This option does not include the standard deviation
    -scaler = StandardScaler(with_std=False)
    -scaler.fit(X)
    -Xscaled = scaler.transform(X)
    -display(XPandas-Xscaled)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Small exercise: perform the standard scaling by including the standard deviation and compare with what Scikit-Learn gives.

    +

    where \( \min(x_j) \) and \( \max(x_j) \) return the minimum and maximum value of \( x_j \) over the data set, respectively.

    @@ -401,7 +358,7 @@ display(XPandas-Xscaled)

  • 37
  • 38
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs029.html b/doc/pub/week35/html/._week35-bs029.html index 0f6fa8c2c..761899986 100644 --- a/doc/pub/week35/html/._week35-bs029.html +++ b/doc/pub/week35/html/._week35-bs029.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,19 +319,102 @@ MathJax.Hub.Config({

     

     

     

    -

    Min-Max Scaling

    +

    Testing the Means Squared Error as function of Complexity

    -

    Another commonly used scaling method is min-max scaling. This is very -useful for when we want the features to lie in a certain interval. To -scale the feature \( x_j \) to the interval \( [a, b] \), we can apply the -transformation +

    One of +the aims is to reproduce Figure 2.11 of Hastie et al.

    -$$ -x_j^{(i)} \rightarrow (b-a)\frac{x_j^{(i)} - \min(x_j)}{\max(x_j) - \min(x_j)} - a -$$ +

    Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points.

    + + +
    +
    +
    +
    +
    +
    np.random.seed()
    +n = 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)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    where \( y \) is the function we want to fit with a given polynomial.

    + +

    Write a first code which sets up a design matrix \( X \) defined by a fourth-order polynomial. Scale your data and split it in training and test data.

    + + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.linear_model import LinearRegression
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.model_selection import train_test_split
    +from sklearn.pipeline import make_pipeline
    +
    +
    +np.random.seed(2018)
    +n = 50
    +maxdegree = 5
    +# 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)
    +TestError = np.zeros(maxdegree)
    +TrainError = np.zeros(maxdegree)
    +polydegree = np.zeros(maxdegree)
    +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
    +scaler = StandardScaler()
    +scaler.fit(x_train)
    +x_train_scaled = scaler.transform(x_train)
    +x_test_scaled = scaler.transform(x_test)
    +
    +for degree in range(maxdegree):
    +    model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
    +    clf = model.fit(x_train_scaled,y_train)
    +    y_fit = clf.predict(x_train_scaled)
    +    y_pred = clf.predict(x_test_scaled) 
    +    polydegree[degree] = degree
    +    TestError[degree] = np.mean( np.mean((y_test - y_pred)**2) )
    +    TrainError[degree] = np.mean( np.mean((y_train - y_fit)**2) )
    +
    +plt.plot(polydegree, TestError, label='Test Error')
    +plt.plot(polydegree, TrainError, label='Train Error')
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    where \( \min(x_j) \) and \( \max(x_j) \) return the minimum and maximum value of \( x_j \) over the data set, respectively.

    @@ -360,7 +441,7 @@ $$

  • 38
  • 39
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs030.html b/doc/pub/week35/html/._week35-bs030.html index efcb96368..1e4b74a19 100644 --- a/doc/pub/week35/html/._week35-bs030.html +++ b/doc/pub/week35/html/._week35-bs030.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,103 +319,38 @@ MathJax.Hub.Config({

     

     

     

    -

    Testing the Means Squared Error as function of Complexity

    +

    Mathematical Interpretation of Ordinary Least Squares

    -

    One of -the aims is to reproduce Figure 2.11 of Hastie et al. +

    What is presented here is a mathematical analysis of various regression algorithms (ordinary least squares, Ridge and Lasso Regression). The analysis is based on an important algorithm in linear algebra, the so-called Singular Value Decomposition (SVD).

    + +

    We have shown that in ordinary least squares the optimal parameters \( \theta \) are given by

    + +$$ +\hat{\boldsymbol{\theta}} = \left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +$$ + +

    The hat over \( \boldsymbol{\theta} \) means we have the optimal parameters after minimization of the cost function.

    + +

    This means that our best model is defined as

    + +$$ +\tilde{\boldsymbol{y}}=\boldsymbol{X}\hat{\boldsymbol{\theta}} = \boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +$$ + +

    We now define a matrix

    +$$ +\boldsymbol{A}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T. +$$ + +

    We can rewrite

    +$$ +\tilde{\boldsymbol{y}}=\boldsymbol{X}\hat{\boldsymbol{\theta}} = \boldsymbol{A}\boldsymbol{y}. +$$ + +

    The matrix \( \boldsymbol{A} \) has the important property that \( \boldsymbol{A}^2=\boldsymbol{A} \). This is the definition of a projection matrix. +We can then interpret our optimal model \( \tilde{\boldsymbol{y}} \) as being represented by an orthogonal projection of \( \boldsymbol{y} \) onto a space defined by the column vectors of \( \boldsymbol{X} \). In our case here the matrix \( \boldsymbol{A} \) is a square matrix. If it is a general rectangular matrix we have an oblique projection matrix.

    -

    Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points.

    - - -
    -
    -
    -
    -
    -
    np.random.seed()
    -n = 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)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    where \( y \) is the function we want to fit with a given polynomial.

    - -

    Write a first code which sets up a design matrix \( X \) defined by a fourth-order polynomial. Scale your data and split it in training and test data.

    - - -
    -
    -
    -
    -
    -
    import matplotlib.pyplot as plt
    -import numpy as np
    -from sklearn.linear_model import LinearRegression
    -from sklearn.preprocessing import PolynomialFeatures
    -from sklearn.model_selection import train_test_split
    -from sklearn.pipeline import make_pipeline
    -
    -
    -np.random.seed(2018)
    -n = 50
    -maxdegree = 5
    -# 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)
    -TestError = np.zeros(maxdegree)
    -TrainError = np.zeros(maxdegree)
    -polydegree = np.zeros(maxdegree)
    -x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
    -scaler = StandardScaler()
    -scaler.fit(x_train)
    -x_train_scaled = scaler.transform(x_train)
    -x_test_scaled = scaler.transform(x_test)
    -
    -for degree in range(maxdegree):
    -    model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
    -    clf = model.fit(x_train_scaled,y_train)
    -    y_fit = clf.predict(x_train_scaled)
    -    y_pred = clf.predict(x_test_scaled) 
    -    polydegree[degree] = degree
    -    TestError[degree] = np.mean( np.mean((y_test - y_pred)**2) )
    -    TrainError[degree] = np.mean( np.mean((y_train - y_fit)**2) )
    -
    -plt.plot(polydegree, TestError, label='Test Error')
    -plt.plot(polydegree, TrainError, label='Train Error')
    -plt.legend()
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    diff --git a/doc/pub/week35/html/._week35-bs031.html b/doc/pub/week35/html/._week35-bs031.html index 336e88315..9adcb5f29 100644 --- a/doc/pub/week35/html/._week35-bs031.html +++ b/doc/pub/week35/html/._week35-bs031.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,37 +319,14 @@ MathJax.Hub.Config({

     

     

     

    -

    Mathematical Interpretation of Ordinary Least Squares

    - -

    What is presented here is a mathematical analysis of various regression algorithms (ordinary least squares, Ridge and Lasso Regression). The analysis is based on an important algorithm in linear algebra, the so-called Singular Value Decomposition (SVD).

    - -

    We have shown that in ordinary least squares the optimal parameters \( \theta \) are given by

    +

    Residual Error

    +

    We have defined the residual error as

    $$ -\hat{\boldsymbol{\theta}} = \left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +\boldsymbol{\epsilon}=\boldsymbol{y}-\tilde{\boldsymbol{y}}=\left[\boldsymbol{I}-\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\right]\boldsymbol{y}. $$ -

    The hat over \( \boldsymbol{\theta} \) means we have the optimal parameters after minimization of the cost function.

    - -

    This means that our best model is defined as

    - -$$ -\tilde{\boldsymbol{y}}=\boldsymbol{X}\hat{\boldsymbol{\theta}} = \boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. -$$ - -

    We now define a matrix

    -$$ -\boldsymbol{A}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T. -$$ - -

    We can rewrite

    -$$ -\tilde{\boldsymbol{y}}=\boldsymbol{X}\hat{\boldsymbol{\theta}} = \boldsymbol{A}\boldsymbol{y}. -$$ - -

    The matrix \( \boldsymbol{A} \) has the important property that \( \boldsymbol{A}^2=\boldsymbol{A} \). This is the definition of a projection matrix. -We can then interpret our optimal model \( \tilde{\boldsymbol{y}} \) as being represented by an orthogonal projection of \( \boldsymbol{y} \) onto a space defined by the column vectors of \( \boldsymbol{X} \). In our case here the matrix \( \boldsymbol{A} \) is a square matrix. If it is a general rectangular matrix we have an oblique projection matrix. -

    +

    The residual errors are then the projections of \( \boldsymbol{y} \) onto the orthogonal component of the space defined by the column vectors of \( \boldsymbol{X} \).

    @@ -378,7 +353,7 @@ We can then interpret our optimal model \( \tilde{\boldsymbol{y}} \) as being re

  • 40
  • 41
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs032.html b/doc/pub/week35/html/._week35-bs032.html index 72da30963..4bf166711 100644 --- a/doc/pub/week35/html/._week35-bs032.html +++ b/doc/pub/week35/html/._week35-bs032.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,14 +319,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Residual Error

    +

    Simple case

    + +

    If the matrix \( \boldsymbol{X} \) is an orthogonal (or unitary in case of complex values) matrix, we have

    -

    We have defined the residual error as

    $$ -\boldsymbol{\epsilon}=\boldsymbol{y}-\tilde{\boldsymbol{y}}=\left[\boldsymbol{I}-\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\right]\boldsymbol{y}. +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{X}\boldsymbol{X}^T = \boldsymbol{I}. $$ -

    The residual errors are then the projections of \( \boldsymbol{y} \) onto the orthogonal component of the space defined by the column vectors of \( \boldsymbol{X} \).

    +

    In this case the matrix \( \boldsymbol{A} \) becomes

    +$$ +\boldsymbol{A}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T)=\boldsymbol{I}, +$$ + +

    and we have the obvious case

    +$$ +\boldsymbol{\epsilon}=\boldsymbol{y}-\tilde{\boldsymbol{y}}=0. +$$ + +

    This serves also as a useful test of our codes.

    @@ -355,7 +364,7 @@ $$

  • 41
  • 42
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs033.html b/doc/pub/week35/html/._week35-bs033.html index 229013477..ca3a84a43 100644 --- a/doc/pub/week35/html/._week35-bs033.html +++ b/doc/pub/week35/html/._week35-bs033.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,25 +319,49 @@ MathJax.Hub.Config({

     

     

     

    -

    Simple case

    +

    The singular value decomposition

    -

    If the matrix \( \boldsymbol{X} \) is an orthogonal (or unitary in case of complex values) matrix, we have

    +
    +
    + -$$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{X}\boldsymbol{X}^T = \boldsymbol{I}. -$$ +

    The examples we have looked at so far are cases where we normally can +invert the matrix \( \boldsymbol{X}^T\boldsymbol{X} \). Using a polynomial expansion where we fit of various functions leads to +row vectors of the design matrix which are essentially orthogonal due +to the polynomial character of our model. Obtaining the inverse of the +design matrix is then often done via a so-called LU, QR or Cholesky +decomposition. +

    -

    In this case the matrix \( \boldsymbol{A} \) becomes

    -$$ -\boldsymbol{A}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T)=\boldsymbol{I}, -$$ +

    As we will also see in the first project, +this may +however not the be case in general and a standard matrix inversion +algorithm based on say LU, QR or Cholesky decomposition may lead to singularities. We will see examples of this below and in other examples. +

    -

    and we have the obvious case

    -$$ -\boldsymbol{\epsilon}=\boldsymbol{y}-\tilde{\boldsymbol{y}}=0. -$$ +

    There is however a way to circumvent this problem and also +gain some insights about the ordinary least squares approach, and +later shrinkage methods like Ridge and Lasso regressions. +

    + +

    This is given by the Singular Value Decomposition (SVD) algorithm, +perhaps the most powerful linear algebra algorithm. The SVD provides +a numerically stable matrix decomposition that is used in a large +swath oc applications and the decomposition is always stable +numerically. +

    + +

    In machine learning it plays a central role in dealing with for +example design matrices that may be near singular or singular. +Furthermore, as we will see here, the singular values can be related +to the covariance matrix (and thereby the correlation matrix) and in +turn the variance of a given quantity. It plays also an important role +in the principal component analysis where high-dimensional data can be +reduced to the statistically relevant features. +

    +
    +
    -

    This serves also as a useful test of our codes.

    @@ -366,7 +388,7 @@ $$

  • 42
  • 43
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs034.html b/doc/pub/week35/html/._week35-bs034.html index b459a865b..ecd7997e9 100644 --- a/doc/pub/week35/html/._week35-bs034.html +++ b/doc/pub/week35/html/._week35-bs034.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,50 +319,55 @@ MathJax.Hub.Config({

     

     

     

    -

    The singular value decomposition

    +

    Linear Regression Problems

    -
    -
    - +

    One of the typical problems we encounter with linear regression, in particular +when the matrix \( \boldsymbol{X} \) (our so-called design matrix) is high-dimensional, +are problems with near singular or singular matrices. The column vectors of \( \boldsymbol{X} \) +may be linearly dependent, normally referred to as super-collinearity. +This means that the matrix may be rank deficient and it is basically impossible to +to model the data using linear regression. As an example, consider the matrix +

    +$$ +\begin{align*} +\mathbf{X} & = \left[ +\begin{array}{rrr} +1 & -1 & 2 +\\ +1 & 0 & 1 +\\ +1 & 2 & -1 +\\ +1 & 1 & 0 +\end{array} \right] +\end{align*} +$$ -

    The examples we have looked at so far are cases where we normally can -invert the matrix \( \boldsymbol{X}^T\boldsymbol{X} \). Using a polynomial expansion where we fit of various functions leads to -row vectors of the design matrix which are essentially orthogonal due -to the polynomial character of our model. Obtaining the inverse of the -design matrix is then often done via a so-called LU, QR or Cholesky -decomposition. +

    The columns of \( \boldsymbol{X} \) are linearly dependent. We see this easily since the +the first column is the row-wise sum of the other two columns. The rank (more correct, +the column rank) of a matrix is the dimension of the space spanned by the +column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number +of linearly independent columns. In this particular case the matrix has rank 2.

    -

    As we will also see in the first project, -this may -however not the be case in general and a standard matrix inversion -algorithm based on say LU, QR or Cholesky decomposition may lead to singularities. We will see examples of this below and in other examples. +

    Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies +that the inverse of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) (the matrix we need to invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this

    +$$ +\begin{align*} +\boldsymbol{X} & = \left[ +\begin{array}{rr} +1 & -1 +\\ +1 & -1 +\end{array} \right]. +\end{align*} +$$ -

    There is however a way to circumvent this problem and also -gain some insights about the ordinary least squares approach, and -later shrinkage methods like Ridge and Lasso regressions. +

    We see easily that \( \mbox{det}(\boldsymbol{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined. +This is equivalent to saying that the matrix \( \boldsymbol{X} \) has at least an eigenvalue which is zero.

    -

    This is given by the Singular Value Decomposition (SVD) algorithm, -perhaps the most powerful linear algebra algorithm. The SVD provides -a numerically stable matrix decomposition that is used in a large -swath oc applications and the decomposition is always stable -numerically. -

    - -

    In machine learning it plays a central role in dealing with for -example design matrices that may be near singular or singular. -Furthermore, as we will see here, the singular values can be related -to the covariance matrix (and thereby the correlation matrix) and in -turn the variance of a given quantity. It plays also an important role -in the principal component analysis where high-dimensional data can be -reduced to the statistically relevant features. -

    -
    -
    - -

      @@ -390,7 +393,7 @@ reduced to the statistically relevant features.
    • 43
    • 44
    • ...
    • -
    • 63
    • +
    • 62
    • »
    diff --git a/doc/pub/week35/html/._week35-bs035.html b/doc/pub/week35/html/._week35-bs035.html index 1b31c695a..202ab4f79 100644 --- a/doc/pub/week35/html/._week35-bs035.html +++ b/doc/pub/week35/html/._week35-bs035.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,54 +319,29 @@ MathJax.Hub.Config({

     

     

     

    -

    Linear Regression Problems

    +

    Fixing the singularity

    -

    One of the typical problems we encounter with linear regression, in particular -when the matrix \( \boldsymbol{X} \) (our so-called design matrix) is high-dimensional, -are problems with near singular or singular matrices. The column vectors of \( \boldsymbol{X} \) -may be linearly dependent, normally referred to as super-collinearity. -This means that the matrix may be rank deficient and it is basically impossible to -to model the data using linear regression. As an example, consider the matrix -

    +

    If our design matrix \( \boldsymbol{X} \) which enters the linear regression problem

    $$ -\begin{align*} -\mathbf{X} & = \left[ -\begin{array}{rrr} -1 & -1 & 2 -\\ -1 & 0 & 1 -\\ -1 & 2 & -1 -\\ -1 & 1 & 0 -\end{array} \right] -\end{align*} +\begin{align} +\boldsymbol{\theta} & = (\boldsymbol{X}^{T} \boldsymbol{X})^{-1} \boldsymbol{X}^{T} \boldsymbol{y}, +\tag{1} +\end{align} $$ -

    The columns of \( \boldsymbol{X} \) are linearly dependent. We see this easily since the -the first column is the row-wise sum of the other two columns. The rank (more correct, -the column rank) of a matrix is the dimension of the space spanned by the -column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number -of linearly independent columns. In this particular case the matrix has rank 2. +

    has linearly dependent column vectors, we will not be able to compute the inverse +of \( \boldsymbol{X}^T\boldsymbol{X} \) and we cannot find the parameters (estimators) \( \theta_i \). +The estimators are only well-defined if \( (\boldsymbol{X}^{T}\boldsymbol{X})^{-1} \) exits. +This is more likely to happen when the matrix \( \boldsymbol{X} \) is high-dimensional. In this case it is likely to encounter a situation where +the regression parameters \( \theta_i \) cannot be estimated.

    -

    Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies -that the inverse of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) (the matrix we need to invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this -

    +

    A cheap ad hoc approach is simply to add a small diagonal component to the matrix to invert, that is we change

    $$ -\begin{align*} -\boldsymbol{X} & = \left[ -\begin{array}{rr} -1 & -1 -\\ -1 & -1 -\end{array} \right]. -\end{align*} +\boldsymbol{X}^{T} \boldsymbol{X} \rightarrow \boldsymbol{X}^{T} \boldsymbol{X}+\lambda \boldsymbol{I}, $$ -

    We see easily that \( \mbox{det}(\boldsymbol{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined. -This is equivalent to saying that the matrix \( \boldsymbol{X} \) has at least an eigenvalue which is zero. -

    +

    where \( \boldsymbol{I} \) is the identity matrix. When we discuss Ridge regression this is actually what we end up evaluating. The parameter \( \lambda \) is called a hyperparameter. More about this later.

    @@ -395,7 +368,7 @@ This is equivalent to saying that the matrix \( \boldsymbol{X} \) has at least a

  • 44
  • 45
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs036.html b/doc/pub/week35/html/._week35-bs036.html index eceb27116..218cc6d5c 100644 --- a/doc/pub/week35/html/._week35-bs036.html +++ b/doc/pub/week35/html/._week35-bs036.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,29 +319,59 @@ MathJax.Hub.Config({

     

     

     

    -

    Fixing the singularity

    +

    Ridge and LASSO Regression

    -

    If our design matrix \( \boldsymbol{X} \) which enters the linear regression problem

    +

    Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is +our optimization problem is +

    $$ -\begin{align} -\boldsymbol{\theta} & = (\boldsymbol{X}^{T} \boldsymbol{X})^{-1} \boldsymbol{X}^{T} \boldsymbol{y}, -\tag{1} -\end{align} +{\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$ -

    has linearly dependent column vectors, we will not be able to compute the inverse -of \( \boldsymbol{X}^T\boldsymbol{X} \) and we cannot find the parameters (estimators) \( \theta_i \). -The estimators are only well-defined if \( (\boldsymbol{X}^{T}\boldsymbol{X})^{-1} \) exits. -This is more likely to happen when the matrix \( \boldsymbol{X} \) is high-dimensional. In this case it is likely to encounter a situation where -the regression parameters \( \theta_i \) cannot be estimated. +

    or we can state it as

    +$$ +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2, +$$ + +

    where we have used the definition of a norm-2 vector, that is

    +$$ +\vert\vert \boldsymbol{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}. +$$ + +

    By minimizing the above equation with respect to the parameters +\( \boldsymbol{\theta} \) we could then obtain an analytical expression for the +parameters \( \boldsymbol{\theta} \). We can add a regularization parameter \( \lambda \) by +defining a new cost function to be optimized, that is

    -

    A cheap ad hoc approach is simply to add a small diagonal component to the matrix to invert, that is we change

    $$ -\boldsymbol{X}^{T} \boldsymbol{X} \rightarrow \boldsymbol{X}^{T} \boldsymbol{X}+\lambda \boldsymbol{I}, +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_2^2 +$$ + +

    which leads to the Ridge regression minimization problem where we +require that \( \vert\vert \boldsymbol{\theta}\vert\vert_2^2\le t \), where \( t \) is +a finite number larger than zero. By defining +

    + +$$ +C(\boldsymbol{X},\boldsymbol{\theta})=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1, +$$ + +

    we have a new optimization equation

    +$$ +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1 +$$ + +

    which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.

    + +

    Here we have defined the norm-1 as

    +$$ +\vert\vert \boldsymbol{x}\vert\vert_1 = \sum_i \vert x_i\vert. $$ -

    where \( \boldsymbol{I} \) is the identity matrix. When we discuss Ridge regression this is actually what we end up evaluating. The parameter \( \lambda \) is called a hyperparameter. More about this later.

    @@ -370,7 +398,7 @@ $$

  • 45
  • 46
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs037.html b/doc/pub/week35/html/._week35-bs037.html index 87e0aa29c..7f210a31f 100644 --- a/doc/pub/week35/html/._week35-bs037.html +++ b/doc/pub/week35/html/._week35-bs037.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,60 +319,152 @@ MathJax.Hub.Config({

     

     

     

    -

    Ridge and LASSO Regression

    +

    Deriving the Ridge Regression Equations

    -

    Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is -our optimization problem is +

    Using the matrix-vector expression for Ridge regression and dropping the parameter \( 1/n \) in front of the standard means squared error equation, we have

    + +$$ +C(\boldsymbol{X},\boldsymbol{\theta})=\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})\right\}+\lambda\boldsymbol{\theta}^T\boldsymbol{\theta}, +$$ + +

    and +taking the derivatives with respect to \( \boldsymbol{\theta} \) we obtain then +a slightly modified matrix inversion problem which for finite values +of \( \lambda \) does not suffer from singularity problems. We obtain +the optimal parameters

    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. +\hat{\boldsymbol{\theta}}_{\mathrm{Ridge}} = \left(\boldsymbol{X}^T\boldsymbol{X}+\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, $$ -

    or we can state it as

    +

    with \( \boldsymbol{I} \) being a \( p\times p \) identity matrix with the constraint that

    + $$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2, +\sum_{i=0}^{p-1} \theta_i^2 \leq t, $$ -

    where we have used the definition of a norm-2 vector, that is

    +

    with \( t \) a finite positive number.

    + +

    If we keep the \( 1/n \) factor, the equation for the optimal \( \theta \) changes to

    $$ -\vert\vert \boldsymbol{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}. +\hat{\boldsymbol{\theta}}_{\mathrm{Ridge}} = \left(\boldsymbol{X}^T\boldsymbol{X}+n\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$ -

    By minimizing the above equation with respect to the parameters -\( \boldsymbol{\theta} \) we could then obtain an analytical expression for the -parameters \( \boldsymbol{\theta} \). We can add a regularization parameter \( \lambda \) by -defining a new cost function to be optimized, that is +

    In many textbooks the \( 1/n \) term is often omitted. Note that a library like Scikit-Learn does not include the \( 1/n \) factor in the setup of the cost function.

    + +

    When we compare this with the ordinary least squares result we have

    +$$ +\hat{\boldsymbol{\theta}}_{\mathrm{OLS}} = \left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, +$$ + +

    which can lead to singular matrices. However, with the SVD, we can always compute the inverse of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \).

    + +

    We see that Ridge regression is nothing but the standard OLS with a +modified diagonal term added to \( \boldsymbol{X}^T\boldsymbol{X} \). The consequences, in +particular for our discussion of the bias-variance tradeoff are rather +interesting. We will see that for specific values of \( \lambda \), we may +even reduce the variance of the optimal parameters \( \boldsymbol{\theta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here.

    -$$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_2^2 -$$ - -

    which leads to the Ridge regression minimization problem where we -require that \( \vert\vert \boldsymbol{\theta}\vert\vert_2^2\le t \), where \( t \) is -a finite number larger than zero. By defining +

    When we have discussed the singular value decomposition of the design +matrix \( \boldsymbol{X} \), we will in turn perform a more rigorous mathematical +discussion of Ridge regression.

    -$$ -C(\boldsymbol{X},\boldsymbol{\theta})=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1, -$$ +

    The code here is a simple demonstration of how to implement Ridge regression with our own code and compare this with scikit-learn.

    -

    we have a new optimization equation

    -$$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1 -$$ -

    which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.

    + +
    +
    +
    +
    +
    +
    import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
     
    -

    Here we have defined the norm-1 as

    -$$ -\vert\vert \boldsymbol{x}\vert\vert_1 = \sum_i \vert x_i\vert. -$$ +def MSE(y_data,y_model): + n = np.size(y_model) + return np.sum((y_data-y_model)**2)/n +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. +np.random.seed(3155) + +n = 100 +x = np.random.rand(n) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) + +Maxpolydegree = 20 +X = np.zeros((n,Maxpolydegree)) +#We include explicitely the intercept column +for degree in range(Maxpolydegree): + 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) + +p = Maxpolydegree +I = np.eye(p,p) +# Decide which values of lambda to use +nlambdas = 6 +MSEOwnRidgePredict = np.zeros(nlambdas) +MSERidgePredict = np.zeros(nlambdas) +lambdas = np.logspace(-4, 2, nlambdas) +for i in range(nlambdas): + lmb = lambdas[i] + OwnRidgeTheta = np.linalg.pinv(X_train.T @ X_train+lmb*I) @ X_train.T @ y_train + # Note: we include the intercept column and no scaling + RegRidge = linear_model.Ridge(lmb,fit_intercept=False) + RegRidge.fit(X_train,y_train) + # and then make the prediction + ytildeOwnRidge = X_train @ OwnRidgeTheta + ypredictOwnRidge = X_test @ OwnRidgeTheta + ytildeRidge = RegRidge.predict(X_train) + ypredictRidge = RegRidge.predict(X_test) + MSEOwnRidgePredict[i] = MSE(y_test,ypredictOwnRidge) + MSERidgePredict[i] = MSE(y_test,ypredictRidge) + print("Theta values for own Ridge implementation") + print(OwnRidgeTheta) + print("Theta values for Scikit-Learn Ridge implementation") + print(RegRidge.coef_) + print("MSE values for own Ridge implementation") + print(MSEOwnRidgePredict[i]) + print("MSE values for Scikit-Learn Ridge implementation") + print(MSERidgePredict[i]) + +# Now plot the results +plt.figure() +plt.plot(np.log10(lambdas), MSEOwnRidgePredict, 'r', label = 'MSE own Ridge Test') +plt.plot(np.log10(lambdas), MSERidgePredict, 'g', label = 'MSE Ridge Test') + +plt.xlabel('log10(lambda)') +plt.ylabel('MSE') +plt.legend() +plt.show() +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    The results here agree when we force Scikit-Learn's Ridge function to include the first column in our design matrix. +We see that the results agree very well. Here we have thus explicitely included the intercept column in the design matrix. +What happens if we do not include the intercept in our fit? We will discuss this in more detail next week. +

    +

    diff --git a/doc/pub/week35/html/._week35-bs038.html b/doc/pub/week35/html/._week35-bs038.html index 47786bb4c..9b11d89e2 100644 --- a/doc/pub/week35/html/._week35-bs038.html +++ b/doc/pub/week35/html/._week35-bs038.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,150 +319,40 @@ MathJax.Hub.Config({

     

     

     

    -

    Deriving the Ridge Regression Equations

    +

    Basic math of the SVD

    -

    Using the matrix-vector expression for Ridge regression and dropping the parameter \( 1/n \) in front of the standard means squared error equation, we have

    - -$$ -C(\boldsymbol{X},\boldsymbol{\theta})=\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})\right\}+\lambda\boldsymbol{\theta}^T\boldsymbol{\theta}, -$$ - -

    and -taking the derivatives with respect to \( \boldsymbol{\theta} \) we obtain then -a slightly modified matrix inversion problem which for finite values -of \( \lambda \) does not suffer from singularity problems. We obtain -the optimal parameters -

    -$$ -\hat{\boldsymbol{\theta}}_{\mathrm{Ridge}} = \left(\boldsymbol{X}^T\boldsymbol{X}+\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, -$$ - -

    with \( \boldsymbol{I} \) being a \( p\times p \) identity matrix with the constraint that

    - -$$ -\sum_{i=0}^{p-1} \theta_i^2 \leq t, -$$ - -

    with \( t \) a finite positive number.

    - -

    If we keep the \( 1/n \) factor, the equation for the optimal \( \theta \) changes to

    -$$ -\hat{\boldsymbol{\theta}}_{\mathrm{Ridge}} = \left(\boldsymbol{X}^T\boldsymbol{X}+n\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. -$$ - -

    In many textbooks the \( 1/n \) term is often omitted. Note that a library like Scikit-Learn does not include the \( 1/n \) factor in the setup of the cost function.

    - -

    When we compare this with the ordinary least squares result we have

    -$$ -\hat{\boldsymbol{\theta}}_{\mathrm{OLS}} = \left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, -$$ - -

    which can lead to singular matrices. However, with the SVD, we can always compute the inverse of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \).

    - -

    We see that Ridge regression is nothing but the standard OLS with a -modified diagonal term added to \( \boldsymbol{X}^T\boldsymbol{X} \). The consequences, in -particular for our discussion of the bias-variance tradeoff are rather -interesting. We will see that for specific values of \( \lambda \), we may -even reduce the variance of the optimal parameters \( \boldsymbol{\theta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here. +

    From standard linear algebra we know that a square matrix \( \boldsymbol{X} \) can be diagonalized if and only if it is +a so-called normal matrix, that is if \( \boldsymbol{X}\in {\mathbb{R}}^{n\times n} \) +we have \( \boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{X}^T\boldsymbol{X} \) or if \( \boldsymbol{X}\in {\mathbb{C}}^{n\times n} \) we have \( \boldsymbol{X}\boldsymbol{X}^{\dagger}=\boldsymbol{X}^{\dagger}\boldsymbol{X} \). +The matrix has then a set of eigenpairs

    -

    When we have discussed the singular value decomposition of the design -matrix \( \boldsymbol{X} \), we will in turn perform a more rigorous mathematical -discussion of Ridge regression. -

    +$$ +(\lambda_1,\boldsymbol{u}_1),\dots, (\lambda_n,\boldsymbol{u}_n), +$$ -

    The code here is a simple demonstration of how to implement Ridge regression with our own code and compare this with scikit-learn.

    +

    and the eigenvalues are given by the diagonal matrix

    +$$ +\boldsymbol{\Sigma}=\mathrm{Diag}(\lambda_1, \dots,\lambda_n). +$$ +

    The matrix \( \boldsymbol{X} \) can be written in terms of an orthogonal/unitary transformation \( \boldsymbol{U} \)

    +$$ +\boldsymbol{X} = \boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, +$$ - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    +

    with \( \boldsymbol{U}\boldsymbol{U}^T=\boldsymbol{I} \) or \( \boldsymbol{U}\boldsymbol{U}^{\dagger}=\boldsymbol{I} \).

    -def MSE(y_data,y_model): - n = np.size(y_model) - return np.sum((y_data-y_model)**2)/n +

    Not all square matrices are diagonalizable. A matrix like the one discussed above

    +$$ +\boldsymbol{X} = \begin{bmatrix} +1& -1 \\ +1& -1\\ +\end{bmatrix} +$$ - -# A seed just to ensure that the random numbers are the same for every run. -# Useful for eventual debugging. -np.random.seed(3155) - -n = 100 -x = np.random.rand(n) -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) - -Maxpolydegree = 20 -X = np.zeros((n,Maxpolydegree)) -#We include explicitely the intercept column -for degree in range(Maxpolydegree): - 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) - -p = Maxpolydegree -I = np.eye(p,p) -# Decide which values of lambda to use -nlambdas = 6 -MSEOwnRidgePredict = np.zeros(nlambdas) -MSERidgePredict = np.zeros(nlambdas) -lambdas = np.logspace(-4, 2, nlambdas) -for i in range(nlambdas): - lmb = lambdas[i] - OwnRidgeTheta = np.linalg.pinv(X_train.T @ X_train+lmb*I) @ X_train.T @ y_train - # Note: we include the intercept column and no scaling - RegRidge = linear_model.Ridge(lmb,fit_intercept=False) - RegRidge.fit(X_train,y_train) - # and then make the prediction - ytildeOwnRidge = X_train @ OwnRidgeTheta - ypredictOwnRidge = X_test @ OwnRidgeTheta - ytildeRidge = RegRidge.predict(X_train) - ypredictRidge = RegRidge.predict(X_test) - MSEOwnRidgePredict[i] = MSE(y_test,ypredictOwnRidge) - MSERidgePredict[i] = MSE(y_test,ypredictRidge) - print("Theta values for own Ridge implementation") - print(OwnRidgeTheta) - print("Theta values for Scikit-Learn Ridge implementation") - print(RegRidge.coef_) - print("MSE values for own Ridge implementation") - print(MSEOwnRidgePredict[i]) - print("MSE values for Scikit-Learn Ridge implementation") - print(MSERidgePredict[i]) - -# Now plot the results -plt.figure() -plt.plot(np.log10(lambdas), MSEOwnRidgePredict, 'r', label = 'MSE own Ridge Test') -plt.plot(np.log10(lambdas), MSERidgePredict, 'g', label = 'MSE Ridge Test') - -plt.xlabel('log10(lambda)') -plt.ylabel('MSE') -plt.legend() -plt.show() -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    The results here agree when we force Scikit-Learn's Ridge function to include the first column in our design matrix. -We see that the results agree very well. Here we have thus explicitely included the intercept column in the design matrix. -What happens if we do not include the intercept in our fit? We will discuss this in more detail next week. +

    is not diagonalizable, it is a so-called defective matrix. It is easy to see that the condition +\( \boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{X}^T\boldsymbol{X} \) is not fulfilled.

    @@ -492,7 +380,7 @@ What happens if we do not include the intercept in our fit? We will discuss this

  • 47
  • 48
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs039.html b/doc/pub/week35/html/._week35-bs039.html index 802ba9af8..c7867b222 100644 --- a/doc/pub/week35/html/._week35-bs039.html +++ b/doc/pub/week35/html/._week35-bs039.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,42 +319,53 @@ MathJax.Hub.Config({

     

     

     

    -

    Basic math of the SVD

    +

    The SVD, a Fantastic Algorithm

    -

    From standard linear algebra we know that a square matrix \( \boldsymbol{X} \) can be diagonalized if and only if it is -a so-called normal matrix, that is if \( \boldsymbol{X}\in {\mathbb{R}}^{n\times n} \) -we have \( \boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{X}^T\boldsymbol{X} \) or if \( \boldsymbol{X}\in {\mathbb{C}}^{n\times n} \) we have \( \boldsymbol{X}\boldsymbol{X}^{\dagger}=\boldsymbol{X}^{\dagger}\boldsymbol{X} \). -The matrix has then a set of eigenpairs +

    However, and this is the strength of the SVD algorithm, any general +matrix \( \boldsymbol{X} \) can be decomposed in terms of a diagonal matrix and +two orthogonal/unitary matrices. The Singular Value Decompostion +(SVD) theorem +states that a general \( m\times n \) matrix \( \boldsymbol{X} \) can be written in +terms of a diagonal matrix \( \boldsymbol{\Sigma} \) of dimensionality \( m\times n \) +and two orthognal matrices \( \boldsymbol{U} \) and \( \boldsymbol{V} \), where the first has +dimensionality \( m \times m \) and the last dimensionality \( n\times n \). +We have then

    -$$ -(\lambda_1,\boldsymbol{u}_1),\dots, (\lambda_n,\boldsymbol{u}_n), +$$ +\boldsymbol{X} = \boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T $$ -

    and the eigenvalues are given by the diagonal matrix

    +

    As an example, the above defective matrix can be decomposed as

    + $$ -\boldsymbol{\Sigma}=\mathrm{Diag}(\lambda_1, \dots,\lambda_n). +\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, $$ -

    The matrix \( \boldsymbol{X} \) can be written in terms of an orthogonal/unitary transformation \( \boldsymbol{U} \)

    -$$ -\boldsymbol{X} = \boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, -$$ - -

    with \( \boldsymbol{U}\boldsymbol{U}^T=\boldsymbol{I} \) or \( \boldsymbol{U}\boldsymbol{U}^{\dagger}=\boldsymbol{I} \).

    - -

    Not all square matrices are diagonalizable. A matrix like the one discussed above

    -$$ -\boldsymbol{X} = \begin{bmatrix} -1& -1 \\ -1& -1\\ -\end{bmatrix} -$$ - -

    is not diagonalizable, it is a so-called defective matrix. It is easy to see that the condition -\( \boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{X}^T\boldsymbol{X} \) is not fulfilled. +

    with eigenvalues \( \sigma_1=2 \) and \( \sigma_2=0 \). +The SVD exits always!

    +

    The SVD +decomposition (singular values) gives eigenvalues +\( \sigma_i\geq\sigma_{i+1} \) for all \( i \) and for dimensions larger than \( i=p \), the +eigenvalues (singular values) are zero. +

    + +

    In the general case, where our design matrix \( \boldsymbol{X} \) has dimension +\( n\times p \), the matrix is thus decomposed into an \( n\times n \) +orthogonal matrix \( \boldsymbol{U} \), a \( p\times p \) orthogonal matrix \( \boldsymbol{V} \) +and a diagonal matrix \( \boldsymbol{\Sigma} \) with \( r=\mathrm{min}(n,p) \) +singular values \( \sigma_i\geq 0 \) on the main diagonal and zeros filling +the rest of the matrix. There are at most \( p \) singular values +assuming that \( n > p \). In our regression examples for the nuclear +masses and the equation of state this is indeed the case, while for +the Ising model we have \( p > n \). These are often cases that lead to +near singular or singular matrices. +

    + +

    The columns of \( \boldsymbol{U} \) are called the left singular vectors while the columns of \( \boldsymbol{V} \) are the right singular vectors.

    +

    diff --git a/doc/pub/week35/html/._week35-bs040.html b/doc/pub/week35/html/._week35-bs040.html index 039c223a7..52b5406e8 100644 --- a/doc/pub/week35/html/._week35-bs040.html +++ b/doc/pub/week35/html/._week35-bs040.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,53 +319,28 @@ MathJax.Hub.Config({

     

     

     

    -

    The SVD, a Fantastic Algorithm

    +

    Economy-size SVD

    -

    However, and this is the strength of the SVD algorithm, any general -matrix \( \boldsymbol{X} \) can be decomposed in terms of a diagonal matrix and -two orthogonal/unitary matrices. The Singular Value Decompostion -(SVD) theorem -states that a general \( m\times n \) matrix \( \boldsymbol{X} \) can be written in -terms of a diagonal matrix \( \boldsymbol{\Sigma} \) of dimensionality \( m\times n \) -and two orthognal matrices \( \boldsymbol{U} \) and \( \boldsymbol{V} \), where the first has -dimensionality \( m \times m \) and the last dimensionality \( n\times n \). -We have then +

    If we assume that \( n > p \), then our matrix \( \boldsymbol{U} \) has dimension \( n +\times n \). The last \( n-p \) columns of \( \boldsymbol{U} \) become however +irrelevant in our calculations since they are multiplied with the +zeros in \( \boldsymbol{\Sigma} \).

    -$$ -\boldsymbol{X} = \boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T -$$ - -

    As an example, the above defective matrix can be decomposed as

    - -$$ -\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, -$$ - -

    with eigenvalues \( \sigma_1=2 \) and \( \sigma_2=0 \). -The SVD exits always! +

    The economy-size decomposition removes extra rows or columns of zeros +from the diagonal matrix of singular values, \( \boldsymbol{\Sigma} \), along with the columns +in either \( \boldsymbol{U} \) or \( \boldsymbol{V} \) that multiply those zeros in the expression. +Removing these zeros and columns can improve execution time +and reduce storage requirements without compromising the accuracy of +the decomposition.

    -

    The SVD -decomposition (singular values) gives eigenvalues -\( \sigma_i\geq\sigma_{i+1} \) for all \( i \) and for dimensions larger than \( i=p \), the -eigenvalues (singular values) are zero. +

    If \( n > p \), we keep only the first \( p \) columns of \( \boldsymbol{U} \) and \( \boldsymbol{\Sigma} \) has dimension \( p\times p \). +If \( p > n \), then only the first \( n \) columns of \( \boldsymbol{V} \) are computed and \( \boldsymbol{\Sigma} \) has dimension \( n\times n \). +The \( n=p \) case is obvious, we retain the full SVD. +In general the economy-size SVD leads to less FLOPS and still conserving the desired accuracy.

    -

    In the general case, where our design matrix \( \boldsymbol{X} \) has dimension -\( n\times p \), the matrix is thus decomposed into an \( n\times n \) -orthogonal matrix \( \boldsymbol{U} \), a \( p\times p \) orthogonal matrix \( \boldsymbol{V} \) -and a diagonal matrix \( \boldsymbol{\Sigma} \) with \( r=\mathrm{min}(n,p) \) -singular values \( \sigma_i\geq 0 \) on the main diagonal and zeros filling -the rest of the matrix. There are at most \( p \) singular values -assuming that \( n > p \). In our regression examples for the nuclear -masses and the equation of state this is indeed the case, while for -the Ising model we have \( p > n \). These are often cases that lead to -near singular or singular matrices. -

    - -

    The columns of \( \boldsymbol{U} \) are called the left singular vectors while the columns of \( \boldsymbol{V} \) are the right singular vectors.

    -

      @@ -393,7 +366,7 @@ near singular or singular matrices.
    • 49
    • 50
    • ...
    • -
    • 63
    • +
    • 62
    • »
    diff --git a/doc/pub/week35/html/._week35-bs041.html b/doc/pub/week35/html/._week35-bs041.html index 083b258f7..a070820d7 100644 --- a/doc/pub/week35/html/._week35-bs041.html +++ b/doc/pub/week35/html/._week35-bs041.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,26 +319,67 @@ MathJax.Hub.Config({

     

     

     

    -

    Economy-size SVD

    +

    Codes for the SVD

    -

    If we assume that \( n > p \), then our matrix \( \boldsymbol{U} \) has dimension \( n -\times n \). The last \( n-p \) columns of \( \boldsymbol{U} \) become however -irrelevant in our calculations since they are multiplied with the -zeros in \( \boldsymbol{\Sigma} \). -

    -

    The economy-size decomposition removes extra rows or columns of zeros -from the diagonal matrix of singular values, \( \boldsymbol{\Sigma} \), along with the columns -in either \( \boldsymbol{U} \) or \( \boldsymbol{V} \) that multiply those zeros in the expression. -Removing these zeros and columns can improve execution time -and reduce storage requirements without compromising the accuracy of -the decomposition. -

    + +
    +
    +
    +
    +
    +
    import numpy as np
    +# SVD inversion
    +def SVD(A):
    +    ''' Takes as input a numpy matrix A and returns inv(A) based on singular value decomposition (SVD).
    +    SVD is numerically more stable than the inversion algorithms provided by
    +    numpy and scipy.linalg at the cost of being slower.
    +    '''
    +    U, S, VT = np.linalg.svd(A,full_matrices=True)
    +    print('test U')
    +    print( (np.transpose(U) @ U - U @np.transpose(U)))
    +    print('test VT')
    +    print( (np.transpose(VT) @ VT - VT @np.transpose(VT)))
    +    print(U)
    +    print(S)
    +    print(VT)
     
    -

    If \( n > p \), we keep only the first \( p \) columns of \( \boldsymbol{U} \) and \( \boldsymbol{\Sigma} \) has dimension \( p\times p \). -If \( p > n \), then only the first \( n \) columns of \( \boldsymbol{V} \) are computed and \( \boldsymbol{\Sigma} \) has dimension \( n\times n \). -The \( n=p \) case is obvious, we retain the full SVD. -In general the economy-size SVD leads to less FLOPS and still conserving the desired accuracy. + D = np.zeros((len(U),len(VT))) + for i in range(0,len(VT)): + D[i,i]=S[i] + return U @ D @ VT + + +X = np.array([ [1.0,-1.0], [1.0,-1.0]]) +#X = np.array([[1, 2], [3, 4], [5, 6]]) + +print(X) +C = SVD(X) +# Print the difference between the original matrix and the SVD one +print(C-X) +

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

    The matrix \( \boldsymbol{X} \) has columns that are linearly dependent. The first +column is the row-wise sum of the other two columns. The rank of a +matrix (the column rank) is the dimension of space spanned by the +column vectors. The rank of the matrix is the number of linearly +independent columns, in this case just \( 2 \). We see this from the +singular values when running the above code. Running the standard +inversion algorithm for matrix inversion with \( \boldsymbol{X}^T\boldsymbol{X} \) results +in the program terminating due to a singular matrix.

    @@ -368,7 +407,7 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des

  • 50
  • 51
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs042.html b/doc/pub/week35/html/._week35-bs042.html index fe08b9cc9..2cd6d1b23 100644 --- a/doc/pub/week35/html/._week35-bs042.html +++ b/doc/pub/week35/html/._week35-bs042.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,67 +319,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Codes for the SVD

    +

    Note about SVD Calculations

    +

    The \( U \), \( S \), and \( V \) matrices returned from the svd() function +cannot be multiplied directly. +

    - -
    -
    -
    -
    -
    -
    import numpy as np
    -# SVD inversion
    -def SVD(A):
    -    ''' Takes as input a numpy matrix A and returns inv(A) based on singular value decomposition (SVD).
    -    SVD is numerically more stable than the inversion algorithms provided by
    -    numpy and scipy.linalg at the cost of being slower.
    -    '''
    -    U, S, VT = np.linalg.svd(A,full_matrices=True)
    -    print('test U')
    -    print( (np.transpose(U) @ U - U @np.transpose(U)))
    -    print('test VT')
    -    print( (np.transpose(VT) @ VT - VT @np.transpose(VT)))
    -    print(U)
    -    print(S)
    -    print(VT)
    +

    As you can see from the code, the \( S \) vector must be converted into a +diagonal matrix. This may cause a problem as the size of the matrices +do not fit the rules of matrix multiplication, where the number of +columns in a matrix must match the number of rows in the subsequent +matrix. +

    - D = np.zeros((len(U),len(VT))) - for i in range(0,len(VT)): - D[i,i]=S[i] - return U @ D @ VT - - -X = np.array([ [1.0,-1.0], [1.0,-1.0]]) -#X = np.array([[1, 2], [3, 4], [5, 6]]) - -print(X) -C = SVD(X) -# Print the difference between the original matrix and the SVD one -print(C-X) -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    The matrix \( \boldsymbol{X} \) has columns that are linearly dependent. The first -column is the row-wise sum of the other two columns. The rank of a -matrix (the column rank) is the dimension of space spanned by the -column vectors. The rank of the matrix is the number of linearly -independent columns, in this case just \( 2 \). We see this from the -singular values when running the above code. Running the standard -inversion algorithm for matrix inversion with \( \boldsymbol{X}^T\boldsymbol{X} \) results -in the program terminating due to a singular matrix. +

    If you wish to include the zero singular values, you will need to +resize the matrices and set up a diagonal matrix as done in the above +example

    @@ -409,7 +362,7 @@ in the program terminating due to a singular matrix.

  • 51
  • 52
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs043.html b/doc/pub/week35/html/._week35-bs043.html index 7ca263705..751040cda 100644 --- a/doc/pub/week35/html/._week35-bs043.html +++ b/doc/pub/week35/html/._week35-bs043.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,23 +319,38 @@ MathJax.Hub.Config({

     

     

     

    -

    Note about SVD Calculations

    +

    Mathematics of the SVD and implications

    -

    The \( U \), \( S \), and \( V \) matrices returned from the svd() function -cannot be multiplied directly. -

    +

    Let us take a closer look at the mathematics of the SVD and the various implications for machine learning studies.

    -

    As you can see from the code, the \( S \) vector must be converted into a -diagonal matrix. This may cause a problem as the size of the matrices -do not fit the rules of matrix multiplication, where the number of -columns in a matrix must match the number of rows in the subsequent -matrix. -

    +

    Our starting point is our design matrix \( \boldsymbol{X} \) of dimension \( n\times p \)

    +$$ +\boldsymbol{X}=\begin{bmatrix} +x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\ +x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\ +x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\ +\dots & \dots & \dots & \dots \dots & \dots \\ +x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\ +x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ +\end{bmatrix}. +$$ -

    If you wish to include the zero singular values, you will need to -resize the matrices and set up a diagonal matrix as done in the above -example -

    +

    We can SVD decompose our matrix as

    +$$ +\boldsymbol{X}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, +$$ + +

    where \( \boldsymbol{U} \) is an orthogonal matrix of dimension \( n\times n \), meaning that \( \boldsymbol{U}\boldsymbol{U}^T=\boldsymbol{U}^T\boldsymbol{U}=\boldsymbol{I}_n \). Here \( \boldsymbol{I}_n \) is the unit matrix of dimension \( n \times n \).

    + +

    Similarly, \( \boldsymbol{V} \) is an orthogonal matrix of dimension \( p\times p \), meaning that \( \boldsymbol{V}\boldsymbol{V}^T=\boldsymbol{V}^T\boldsymbol{V}=\boldsymbol{I}_p \). Here \( \boldsymbol{I}_n \) is the unit matrix of dimension \( p \times p \).

    + +

    Finally \( \boldsymbol{\Sigma} \) contains the singular values \( \sigma_i \). This matrix has dimension \( n\times p \) and the singular values \( \sigma_i \) are all positive. The non-zero values are ordered in descending order, that is

    + +$$ +\sigma_0 > \sigma_1 > \sigma_2 > \dots > \sigma_{p-1} > 0. +$$ + +

    All values beyond \( p-1 \) are all zero.

    @@ -364,7 +377,7 @@ example

  • 52
  • 53
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs044.html b/doc/pub/week35/html/._week35-bs044.html index e5de836c3..7a6c1cbad 100644 --- a/doc/pub/week35/html/._week35-bs044.html +++ b/doc/pub/week35/html/._week35-bs044.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,38 +319,62 @@ MathJax.Hub.Config({

     

     

     

    -

    Mathematics of the SVD and implications

    +

    Example Matrix

    -

    Let us take a closer look at the mathematics of the SVD and the various implications for machine learning studies.

    - -

    Our starting point is our design matrix \( \boldsymbol{X} \) of dimension \( n\times p \)

    -$$ -\boldsymbol{X}=\begin{bmatrix} -x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\ -x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\ -x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\ -\dots & \dots & \dots & \dots \dots & \dots \\ -x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\ -x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ -\end{bmatrix}. -$$ - -

    We can SVD decompose our matrix as

    -$$ -\boldsymbol{X}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, -$$ - -

    where \( \boldsymbol{U} \) is an orthogonal matrix of dimension \( n\times n \), meaning that \( \boldsymbol{U}\boldsymbol{U}^T=\boldsymbol{U}^T\boldsymbol{U}=\boldsymbol{I}_n \). Here \( \boldsymbol{I}_n \) is the unit matrix of dimension \( n \times n \).

    - -

    Similarly, \( \boldsymbol{V} \) is an orthogonal matrix of dimension \( p\times p \), meaning that \( \boldsymbol{V}\boldsymbol{V}^T=\boldsymbol{V}^T\boldsymbol{V}=\boldsymbol{I}_p \). Here \( \boldsymbol{I}_n \) is the unit matrix of dimension \( p \times p \).

    - -

    Finally \( \boldsymbol{\Sigma} \) contains the singular values \( \sigma_i \). This matrix has dimension \( n\times p \) and the singular values \( \sigma_i \) are all positive. The non-zero values are ordered in descending order, that is

    +

    As an example, consider the following \( 3\times 2 \) example for the matrix \( \boldsymbol{\Sigma} \)

    $$ -\sigma_0 > \sigma_1 > \sigma_2 > \dots > \sigma_{p-1} > 0. +\boldsymbol{\Sigma}= +\begin{bmatrix} +2& 0 \\ +0 & 1 \\ +0 & 0 \\ +\end{bmatrix} $$ -

    All values beyond \( p-1 \) are all zero.

    +

    The singular values are \( \sigma_0=2 \) and \( \sigma_1=1 \). It is common to rewrite the matrix \( \boldsymbol{\Sigma} \) as

    + +$$ +\boldsymbol{\Sigma}= +\begin{bmatrix} +\boldsymbol{\tilde{\Sigma}}\\ +\boldsymbol{0}\\ +\end{bmatrix}, +$$ + +

    where

    +$$ +\boldsymbol{\tilde{\Sigma}}= +\begin{bmatrix} +2& 0 \\ +0 & 1 \\ +\end{bmatrix}, +$$ + +

    contains only the singular values. Note also (and we will use this below) that

    + +$$ +\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}= +\begin{bmatrix} +4& 0 \\ +0 & 1 \\ +\end{bmatrix}, +$$ + +

    which is a \( 2\times 2 \) matrix while

    +$$ +\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T= +\begin{bmatrix} +4& 0 & 0\\ +0 & 1 & 0\\ +0 & 0 & 0\\ +\end{bmatrix}, +$$ + +

    is a \( 3\times 3 \) matrix. The last row and column of this last matrix +contain only zeros. This will have important consequences for our SVD +decomposition of the design matrix. +

    @@ -379,7 +401,7 @@ $$

  • 53
  • 54
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs045.html b/doc/pub/week35/html/._week35-bs045.html index a3e921925..e2c994e45 100644 --- a/doc/pub/week35/html/._week35-bs045.html +++ b/doc/pub/week35/html/._week35-bs045.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,61 +319,47 @@ MathJax.Hub.Config({

     

     

     

    -

    Example Matrix

    +

    Setting up the Matrix to be inverted

    -

    As an example, consider the following \( 3\times 2 \) example for the matrix \( \boldsymbol{\Sigma} \)

    +

    The matrix that may cause problems for us is \( \boldsymbol{X}^T\boldsymbol{X} \). Using the SVD we can rewrite this matrix as

    $$ -\boldsymbol{\Sigma}= -\begin{bmatrix} -2& 0 \\ -0 & 1 \\ -0 & 0 \\ -\end{bmatrix} +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, $$ -

    The singular values are \( \sigma_0=2 \) and \( \sigma_1=1 \). It is common to rewrite the matrix \( \boldsymbol{\Sigma} \) as

    +

    and using the orthogonality of the matrix \( \boldsymbol{U} \) we have

    $$ -\boldsymbol{\Sigma}= -\begin{bmatrix} -\boldsymbol{\tilde{\Sigma}}\\ -\boldsymbol{0}\\ -\end{bmatrix}, +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. $$ -

    where

    -$$ -\boldsymbol{\tilde{\Sigma}}= -\begin{bmatrix} -2& 0 \\ -0 & 1 \\ -\end{bmatrix}, -$$ +

    We define \( \boldsymbol{\Sigma}^T\boldsymbol{\Sigma}=\tilde{\boldsymbol{\Sigma}}^2 \) which is a diagonal matrix containing only the singular values squared. It has dimensionality \( p \times p \).

    -

    contains only the singular values. Note also (and we will use this below) that

    +

    We can now insert the result for the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) into our equation for ordinary least squares where

    $$ -\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}= -\begin{bmatrix} -4& 0 \\ -0 & 1 \\ -\end{bmatrix}, +\tilde{y}_{\mathrm{OLS}}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, $$ -

    which is a \( 2\times 2 \) matrix while

    +

    and using our SVD decomposition of \( \boldsymbol{X} \) we have

    + $$ -\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T= -\begin{bmatrix} -4& 0 & 0\\ -0 & 1 & 0\\ -0 & 0 & 0\\ -\end{bmatrix}, +\tilde{y}_{\mathrm{OLS}}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\left(\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^{2}(\boldsymbol{V}^T\right)^{-1}\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{y}, $$ -

    is a \( 3\times 3 \) matrix. The last row and column of this last matrix -contain only zeros. This will have important consequences for our SVD -decomposition of the design matrix. +

    which gives us, using the orthogonality of the matrix \( \boldsymbol{V} \),

    + +$$ +\tilde{y}_{\mathrm{OLS}}=\boldsymbol{U}\boldsymbol{U}^T\boldsymbol{y}=\sum_{i=0}^{p-1}\boldsymbol{u}_i\boldsymbol{u}^T_i\boldsymbol{y}, +$$ + +

    It means that the ordinary least square model (with the optimal +parameters) \( \boldsymbol{\tilde{y}} \), corresponds to an orthogonal +transformation of the output (or target) vector \( \boldsymbol{y} \) by the +vectors of the matrix \( \boldsymbol{U} \). Note that the summation ends at +\( p-1 \), that is \( \boldsymbol{\tilde{y}}\ne \boldsymbol{y} \). We can thus not use the +orthogonality relation for the matrix \( \boldsymbol{U} \). This can already be +when we multiply the matrices \( \boldsymbol{\Sigma}^T\boldsymbol{U}^T \).

    @@ -403,7 +387,7 @@ decomposition of the design matrix.

  • 54
  • 55
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs046.html b/doc/pub/week35/html/._week35-bs046.html index ed2262d2f..83e41edf6 100644 --- a/doc/pub/week35/html/._week35-bs046.html +++ b/doc/pub/week35/html/._week35-bs046.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,47 +319,52 @@ MathJax.Hub.Config({

     

     

     

    -

    Setting up the Matrix to be inverted

    - -

    The matrix that may cause problems for us is \( \boldsymbol{X}^T\boldsymbol{X} \). Using the SVD we can rewrite this matrix as

    +

    Further properties (important for our analyses later)

    +

    Let us study again \( \boldsymbol{X}^T\boldsymbol{X} \) in terms of our SVD,

    $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. $$ -

    and using the orthogonality of the matrix \( \boldsymbol{U} \) we have

    - +

    If we now multiply from the right with \( \boldsymbol{V} \) (using the orthogonality of \( \boldsymbol{V} \)) we get

    $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. +\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{V}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}. $$ -

    We define \( \boldsymbol{\Sigma}^T\boldsymbol{\Sigma}=\tilde{\boldsymbol{\Sigma}}^2 \) which is a diagonal matrix containing only the singular values squared. It has dimensionality \( p \times p \).

    - -

    We can now insert the result for the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) into our equation for ordinary least squares where

    - +

    This means the vectors \( \boldsymbol{v}_i \) of the orthogonal matrix \( \boldsymbol{V} \) are the eigenvectors of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) +with eigenvalues given by the singular values squared, that is +

    $$ -\tilde{y}_{\mathrm{OLS}}=\boldsymbol{X}\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}, +\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. $$ -

    and using our SVD decomposition of \( \boldsymbol{X} \) we have

    - +

    Similarly, if we use the SVD decomposition for the matrix \( \boldsymbol{X}\boldsymbol{X}^T \), we have

    $$ -\tilde{y}_{\mathrm{OLS}}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\left(\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^{2}(\boldsymbol{V}^T\right)^{-1}\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{y}, +\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T\boldsymbol{U}^T. $$ -

    which gives us, using the orthogonality of the matrix \( \boldsymbol{V} \),

    - +

    If we now multiply from the right with \( \boldsymbol{U} \) (using the orthogonality of \( \boldsymbol{U} \)) we get

    $$ -\tilde{y}_{\mathrm{OLS}}=\boldsymbol{U}\boldsymbol{U}^T\boldsymbol{y}=\sum_{i=0}^{p-1}\boldsymbol{u}_i\boldsymbol{u}^T_i\boldsymbol{y}, +\left(\boldsymbol{X}\boldsymbol{X}^T\right)\boldsymbol{U}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T. $$ -

    It means that the ordinary least square model (with the optimal -parameters) \( \boldsymbol{\tilde{y}} \), corresponds to an orthogonal -transformation of the output (or target) vector \( \boldsymbol{y} \) by the -vectors of the matrix \( \boldsymbol{U} \). Note that the summation ends at -\( p-1 \), that is \( \boldsymbol{\tilde{y}}\ne \boldsymbol{y} \). We can thus not use the -orthogonality relation for the matrix \( \boldsymbol{U} \). This can already be -when we multiply the matrices \( \boldsymbol{\Sigma}^T\boldsymbol{U}^T \). +

    This means the vectors \( \boldsymbol{u}_i \) of the orthogonal matrix \( \boldsymbol{U} \) are the eigenvectors of the matrix \( \boldsymbol{X}\boldsymbol{X}^T \) +with eigenvalues given by the singular values squared, that is +

    +$$ +\left(\boldsymbol{X}\boldsymbol{X}^T\right)\boldsymbol{u}_i=\boldsymbol{u}_i\sigma_i^2. +$$ + +

    Important note: we have defined our design matrix \( \boldsymbol{X} \) to be an +\( n\times p \) matrix. In most supervised learning cases we have that \( n +\ge p \), and quite often we have \( n >> p \). For linear algebra based methods like ordinary least squares or Ridge regression, this leads to a matrix \( \boldsymbol{X}^T\boldsymbol{X} \) which is small and thereby easier to handle from a computational point of view (in terms of number of floating point operations). +

    + +

    In our lectures, the number of columns will +always refer to the number of features in our data set, while the +number of rows represents the number of data inputs. Note that in +other texts you may find the opposite notation. This has consequences +for the definition of for example the covariance matrix and its relation to the SVD.

    @@ -389,7 +392,7 @@ when we multiply the matrices \( \boldsymbol{\Sigma}^T\boldsymbol{U}^T \).

  • 55
  • 56
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs047.html b/doc/pub/week35/html/._week35-bs047.html index 84ddca4e3..fa7360c2c 100644 --- a/doc/pub/week35/html/._week35-bs047.html +++ b/doc/pub/week35/html/._week35-bs047.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,52 +319,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Further properties (important for our analyses later)

    +

    Meet the Covariance Matrix

    -

    Let us study again \( \boldsymbol{X}^T\boldsymbol{X} \) in terms of our SVD,

    -$$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. -$$ +

    Before we move on to a discussion of Ridge and Lasso regression, we want to show an important example of the above.

    -

    If we now multiply from the right with \( \boldsymbol{V} \) (using the orthogonality of \( \boldsymbol{V} \)) we get

    -$$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{V}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}. -$$ - -

    This means the vectors \( \boldsymbol{v}_i \) of the orthogonal matrix \( \boldsymbol{V} \) are the eigenvectors of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) -with eigenvalues given by the singular values squared, that is -

    -$$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. -$$ - -

    Similarly, if we use the SVD decomposition for the matrix \( \boldsymbol{X}\boldsymbol{X}^T \), we have

    -$$ -\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T\boldsymbol{U}^T. -$$ - -

    If we now multiply from the right with \( \boldsymbol{U} \) (using the orthogonality of \( \boldsymbol{U} \)) we get

    -$$ -\left(\boldsymbol{X}\boldsymbol{X}^T\right)\boldsymbol{U}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T. -$$ - -

    This means the vectors \( \boldsymbol{u}_i \) of the orthogonal matrix \( \boldsymbol{U} \) are the eigenvectors of the matrix \( \boldsymbol{X}\boldsymbol{X}^T \) -with eigenvalues given by the singular values squared, that is -

    -$$ -\left(\boldsymbol{X}\boldsymbol{X}^T\right)\boldsymbol{u}_i=\boldsymbol{u}_i\sigma_i^2. -$$ - -

    Important note: we have defined our design matrix \( \boldsymbol{X} \) to be an -\( n\times p \) matrix. In most supervised learning cases we have that \( n -\ge p \), and quite often we have \( n >> p \). For linear algebra based methods like ordinary least squares or Ridge regression, this leads to a matrix \( \boldsymbol{X}^T\boldsymbol{X} \) which is small and thereby easier to handle from a computational point of view (in terms of number of floating point operations). +

    We have already noted that the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) in ordinary +least squares is proportional to the second derivative of the cost +function, that is we have

    -

    In our lectures, the number of columns will -always refer to the number of features in our data set, while the -number of rows represents the number of data inputs. Note that in -other texts you may find the opposite notation. This has consequences -for the definition of for example the covariance matrix and its relation to the SVD. +$$ +\frac{\partial^2 C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}\partial \boldsymbol{\theta}^T} =\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    This quantity defines was what is called the Hessian matrix (the second derivative of a function we want to optimize).

    + +

    The Hessian matrix plays an important role and is defined in this course as

    + +$$ +\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    The Hessian matrix for ordinary least squares is also proportional to +the covariance matrix. This means also that we can use the SVD to find +the eigenvalues of the covariance matrix and the Hessian matrix in +terms of the singular values. Let us develop these arguments, as they will play an important role in our machine learning studies.

    @@ -394,7 +371,7 @@ for the definition of for example the covariance matrix and its relation to the

  • 56
  • 57
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs048.html b/doc/pub/week35/html/._week35-bs048.html index fa591f6ce..ae680dd81 100644 --- a/doc/pub/week35/html/._week35-bs048.html +++ b/doc/pub/week35/html/._week35-bs048.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,31 +319,46 @@ MathJax.Hub.Config({

     

     

     

    -

    Meet the Covariance Matrix

    +

    Introducing the Covariance and Correlation functions

    -

    Before we move on to a discussion of Ridge and Lasso regression, we want to show an important example of the above.

    - -

    We have already noted that the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) in ordinary -least squares is proportional to the second derivative of the cost -function, that is we have +

    Before we discuss the link between for example Ridge regression and the singular value decomposition, we need to remind ourselves about +the definition of the covariance and the correlation function. These are quantities that play a central role in machine learning methods.

    +

    Suppose we have defined two vectors +\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as +

    $$ -\frac{\partial^2 C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}\partial \boldsymbol{\theta}^T} =\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{cov}[\boldsymbol{x},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ + \mathrm{cov}[\boldsymbol{y},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{y},\boldsymbol{y}] \\ + \end{bmatrix}, $$ -

    This quantity defines was what is called the Hessian matrix (the second derivative of a function we want to optimize).

    - -

    The Hessian matrix plays an important role and is defined in this course as

    - +

    where for example

    $$ -\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). $$ -

    The Hessian matrix for ordinary least squares is also proportional to -the covariance matrix. This means also that we can use the SVD to find -the eigenvalues of the covariance matrix and the Hessian matrix in -terms of the singular values. Let us develop these arguments, as they will play an important role in our machine learning studies. +

    With this definition and recalling that the variance is defined as

    +$$ +\mathrm{var}[\boldsymbol{x}]=\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})^2, +$$ + +

    we can rewrite the covariance matrix as

    +$$ +\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{var}[\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ + \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] & \mathrm{var}[\boldsymbol{y}] \\ + \end{bmatrix}. +$$ + +

    Note: we have used \( 1/n \) in the above definitions of the sample variance and covariance. We assume then that we can calculate the exact mean value. +What you will find in essentially all statistics texts are equations +with a factor \( 1/(n-1) \). This is called Bessel's correction. This +method corrects the bias in the estimation of the population variance +and covariance. It also partially corrects the bias in the estimation +of the population standard deviation. If you use a library like +Scikit-Learn or nunmpy's function to calculate the covariance, this +quantity will be computed with a factor \( 1/(n-1) \).

    @@ -373,7 +386,7 @@ terms of the singular values. Let us develop these arguments, as they will pla

  • 57
  • 58
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs049.html b/doc/pub/week35/html/._week35-bs049.html index f1ddc4dc6..18933937e 100644 --- a/doc/pub/week35/html/._week35-bs049.html +++ b/doc/pub/week35/html/._week35-bs049.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,47 +319,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Introducing the Covariance and Correlation functions

    +

    Covariance and Correlation Matrix

    -

    Before we discuss the link between for example Ridge regression and the singular value decomposition, we need to remind ourselves about -the definition of the covariance and the correlation function. These are quantities that play a central role in machine learning methods. +

    The covariance takes values between zero and infinity and may thus +lead to problems with loss of numerical precision for particularly +large values. It is common to scale the covariance matrix by +introducing instead the correlation matrix defined via the so-called +correlation function

    -

    Suppose we have defined two vectors -\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as -

    $$ -\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{cov}[\boldsymbol{x},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ - \mathrm{cov}[\boldsymbol{y},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{y},\boldsymbol{y}] \\ +\mathrm{corr}[\boldsymbol{x},\boldsymbol{y}]=\frac{\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{\mathrm{var}[\boldsymbol{x}] \mathrm{var}[\boldsymbol{y}]}}. +$$ + +

    The correlation function is then given by values \( \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] +\in [-1,1] \). This avoids eventual problems with too large values. We +can then define the correlation matrix for the two vectors \( \boldsymbol{x} \) +and \( \boldsymbol{y} \) as +

    + +$$ +\boldsymbol{K}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \\ + \mathrm{corr}[\boldsymbol{y},\boldsymbol{x}] & 1 \\ \end{bmatrix}, $$ -

    where for example

    -$$ -\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). -$$ - -

    With this definition and recalling that the variance is defined as

    -$$ -\mathrm{var}[\boldsymbol{x}]=\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})^2, -$$ - -

    we can rewrite the covariance matrix as

    -$$ -\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{var}[\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ - \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] & \mathrm{var}[\boldsymbol{y}] \\ - \end{bmatrix}. -$$ - -

    Note: we have used \( 1/n \) in the above definitions of the sample variance and covariance. We assume then that we can calculate the exact mean value. -What you will find in essentially all statistics texts are equations -with a factor \( 1/(n-1) \). This is called Bessel's correction. This -method corrects the bias in the estimation of the population variance -and covariance. It also partially corrects the bias in the estimation -of the population standard deviation. If you use a library like -Scikit-Learn or nunmpy's function to calculate the covariance, this -quantity will be computed with a factor \( 1/(n-1) \). -

    +

    In the above example this is the function we constructed using pandas.

    @@ -388,7 +371,7 @@ quantity will be computed with a factor \( 1/(n-1) \).

  • 58
  • 59
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs050.html b/doc/pub/week35/html/._week35-bs050.html index f20cdad91..641905ec1 100644 --- a/doc/pub/week35/html/._week35-bs050.html +++ b/doc/pub/week35/html/._week35-bs050.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,32 +319,65 @@ MathJax.Hub.Config({

     

     

     

    -

    Covariance and Correlation Matrix

    +

    Correlation Function and Design/Feature Matrix

    -

    The covariance takes values between zero and infinity and may thus -lead to problems with loss of numerical precision for particularly -large values. It is common to scale the covariance matrix by -introducing instead the correlation matrix defined via the so-called -correlation function +

    In our derivation of the various regression algorithms like Ordinary Least Squares or Ridge regression +we defined the design/feature matrix \( \boldsymbol{X} \) as

    $$ -\mathrm{corr}[\boldsymbol{x},\boldsymbol{y}]=\frac{\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{\mathrm{var}[\boldsymbol{x}] \mathrm{var}[\boldsymbol{y}]}}. +\boldsymbol{X}=\begin{bmatrix} +x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\ +x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\ +x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\ +\dots & \dots & \dots & \dots \dots & \dots \\ +x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\ +x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ +\end{bmatrix}, $$ -

    The correlation function is then given by values \( \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] -\in [-1,1] \). This avoids eventual problems with too large values. We -can then define the correlation matrix for the two vectors \( \boldsymbol{x} \) -and \( \boldsymbol{y} \) as +

    with \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors/features \( p \) refering to the column numbers and the +entries \( n \) being the row elements. +We can rewrite the design/feature matrix in terms of its column vectors as +

    +$$ +\boldsymbol{X}=\begin{bmatrix} \boldsymbol{x}_0 & \boldsymbol{x}_1 & \boldsymbol{x}_2 & \dots & \dots & \boldsymbol{x}_{p-1}\end{bmatrix}, +$$ + +

    with a given vector

    +$$ +\boldsymbol{x}_i^T = \begin{bmatrix}x_{0,i} & x_{1,i} & x_{2,i}& \dots & \dots x_{n-1,i}\end{bmatrix}. +$$ + +

    With these definitions, we can now rewrite our \( 2\times 2 \) +correlation/covariance matrix in terms of a moe general design/feature +matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \). This leads to a \( p\times p \) +covariance matrix for the vectors \( \boldsymbol{x}_i \) with \( i=0,1,\dots,p-1 \)

    $$ -\boldsymbol{K}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \\ - \mathrm{corr}[\boldsymbol{y},\boldsymbol{x}] & 1 \\ - \end{bmatrix}, +\boldsymbol{C}[\boldsymbol{x}] = \begin{bmatrix} +\mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ +\mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ +\mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_1] & \mathrm{var}[\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ +\dots & \dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots & \dots \\ +\mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & \mathrm{var}[\boldsymbol{x}_{p-1}]\\ +\end{bmatrix}, +$$ + +

    and the correlation matrix

    +$$ +\boldsymbol{K}[\boldsymbol{x}] = \begin{bmatrix} +1 & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ +\mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_0] & 1 & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ +\mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_1] & 1 & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ +\dots & \dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots & \dots \\ +\mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & 1\\ +\end{bmatrix}, $$ -

    In the above example this is the function we constructed using pandas.

    @@ -373,7 +404,7 @@ $$

  • 59
  • 60
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs051.html b/doc/pub/week35/html/._week35-bs051.html index d22d74d13..9714b6ad2 100644 --- a/doc/pub/week35/html/._week35-bs051.html +++ b/doc/pub/week35/html/._week35-bs051.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,64 +319,60 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Function and Design/Feature Matrix

    +

    Covariance Matrix Examples

    -

    In our derivation of the various regression algorithms like Ordinary Least Squares or Ridge regression -we defined the design/feature matrix \( \boldsymbol{X} \) as +

    The Numpy function np.cov calculates the covariance elements using +the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have +the exact mean values. The following simple function uses the +np.vstack function which takes each vector of dimension \( 1\times n \) +and produces a \( 2\times n \) matrix \( \boldsymbol{W} \)

    +

    Note that this assumes you have the features as the rows, and the inputs as columns, that is

    $$ -\boldsymbol{X}=\begin{bmatrix} -x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\ -x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\ -x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\ -\dots & \dots & \dots & \dots \dots & \dots \\ -x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\ -x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ -\end{bmatrix}, +\boldsymbol{W} = \begin{bmatrix} x_0 & x_1 & x_2 & \dots & x_{n-2} & x_{n-1} \\ + y_0 & y_1 & y_2 & \dots & y_{n-2} & y_{n-1} \\ + \end{bmatrix}, $$ -

    with \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors/features \( p \) refering to the column numbers and the -entries \( n \) being the row elements. -We can rewrite the design/feature matrix in terms of its column vectors as -

    -$$ -\boldsymbol{X}=\begin{bmatrix} \boldsymbol{x}_0 & \boldsymbol{x}_1 & \boldsymbol{x}_2 & \dots & \dots & \boldsymbol{x}_{p-1}\end{bmatrix}, -$$ - -

    with a given vector

    -$$ -\boldsymbol{x}_i^T = \begin{bmatrix}x_{0,i} & x_{1,i} & x_{2,i}& \dots & \dots x_{n-1,i}\end{bmatrix}. -$$ - -

    With these definitions, we can now rewrite our \( 2\times 2 \) -correlation/covariance matrix in terms of a moe general design/feature -matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \). This leads to a \( p\times p \) -covariance matrix for the vectors \( \boldsymbol{x}_i \) with \( i=0,1,\dots,p-1 \) +

    which in turn is converted into into the \( 2\times 2 \) covariance matrix +\( \boldsymbol{C} \) via the Numpy function np.cov(). We note that we can also calculate +the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy +function np.mean(x). We can also extract the eigenvalues of the +covariance matrix through the np.linalg.eig() function.

    -$$ -\boldsymbol{C}[\boldsymbol{x}] = \begin{bmatrix} -\mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ -\mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ -\mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_1] & \mathrm{var}[\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ -\dots & \dots & \dots & \dots & \dots & \dots \\ -\dots & \dots & \dots & \dots & \dots & \dots \\ -\mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & \mathrm{var}[\boldsymbol{x}_{p-1}]\\ -\end{bmatrix}, -$$ -

    and the correlation matrix

    -$$ -\boldsymbol{K}[\boldsymbol{x}] = \begin{bmatrix} -1 & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ -\mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_0] & 1 & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ -\mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_1] & 1 & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ -\dots & \dots & \dots & \dots & \dots & \dots \\ -\dots & \dots & \dots & \dots & \dots & \dots \\ -\mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & 1\\ -\end{bmatrix}, -$$ + +
    +
    +
    +
    +
    +
    # Importing various packages
    +import numpy as np
    +n = 100
    +x = np.random.normal(size=n)
    +print(np.mean(x))
    +y = 4+3*x+np.random.normal(size=n)
    +print(np.mean(y))
    +W = np.vstack((x, y))
    +C = np.cov(W)
    +print(C)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -406,7 +400,7 @@ $$

  • 60
  • 61
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs052.html b/doc/pub/week35/html/._week35-bs052.html index 96d7056aa..51a79daf9 100644 --- a/doc/pub/week35/html/._week35-bs052.html +++ b/doc/pub/week35/html/._week35-bs052.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,27 +319,13 @@ MathJax.Hub.Config({

     

     

     

    -

    Covariance Matrix Examples

    +

    Correlation Matrix

    -

    The Numpy function np.cov calculates the covariance elements using -the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have -the exact mean values. The following simple function uses the -np.vstack function which takes each vector of dimension \( 1\times n \) -and produces a \( 2\times n \) matrix \( \boldsymbol{W} \) -

    - -

    Note that this assumes you have the features as the rows, and the inputs as columns, that is

    -$$ -\boldsymbol{W} = \begin{bmatrix} x_0 & x_1 & x_2 & \dots & x_{n-2} & x_{n-1} \\ - y_0 & y_1 & y_2 & \dots & y_{n-2} & y_{n-1} \\ - \end{bmatrix}, -$$ - -

    which in turn is converted into into the \( 2\times 2 \) covariance matrix -\( \boldsymbol{C} \) via the Numpy function np.cov(). We note that we can also calculate -the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy -function np.mean(x). We can also extract the eigenvalues of the -covariance matrix through the np.linalg.eig() function. +

    The previous example can be converted into the correlation matrix by +simply scaling the matrix elements with the variances. We should also +subtract the mean values for each column. This leads to the following +code which sets up the correlations matrix for the previous example in +a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors).

    @@ -351,15 +335,26 @@ covariance matrix through the np.linalg.eig() function.
    -
    # Importing various packages
    -import numpy as np
    +  
    import numpy as np
     n = 100
    -x = np.random.normal(size=n)
    -print(np.mean(x))
    +# define two vectors                                                                                           
    +x = np.random.random(size=n)
     y = 4+3*x+np.random.normal(size=n)
    -print(np.mean(y))
    -W = np.vstack((x, y))
    -C = np.cov(W)
    +#scaling the x and y vectors                                                                                   
    +x = x - np.mean(x)
    +y = y - np.mean(y)
    +variance_x = np.sum(x@x)/n
    +variance_y = np.sum(y@y)/n
    +print(variance_x)
    +print(variance_y)
    +cov_xy = np.sum(x@y)/n
    +cov_xx = np.sum(x@x)/n
    +cov_yy = np.sum(y@y)/n
    +C = np.zeros((2,2))
    +C[0,0]= cov_xx/variance_x
    +C[1,1]= cov_yy/variance_y
    +C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
    +C[1,0]= C[0,1]
     print(C)
     
    @@ -376,6 +371,12 @@ C = np.c
    +

    We see that the matrix elements along the diagonal are one as they +should be and that the matrix is symmetric. Furthermore, diagonalizing +this matrix we easily see that it is a positive definite matrix. +

    + +

    The above procedure with numpy can be made more compact if we use pandas.

    @@ -401,8 +402,6 @@ C = np.c

  • 60
  • 61
  • 62
  • -
  • ...
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs053.html b/doc/pub/week35/html/._week35-bs053.html index 273a3d2ea..ccc0caa02 100644 --- a/doc/pub/week35/html/._week35-bs053.html +++ b/doc/pub/week35/html/._week35-bs053.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,15 +319,9 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Matrix

    - -

    The previous example can be converted into the correlation matrix by -simply scaling the matrix elements with the variances. We should also -subtract the mean values for each column. This leads to the following -code which sets up the correlations matrix for the previous example in -a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors). -

    +

    Correlation Matrix with Pandas

    +

    We whow here how we can set up the correlation matrix using pandas, as done in this simple code

    @@ -338,26 +330,19 @@ a more brute force way. Here we scale the mean values for each column of the des
    import numpy as np
    -n = 100
    -# define two vectors                                                                                           
    -x = np.random.random(size=n)
    -y = 4+3*x+np.random.normal(size=n)
    -#scaling the x and y vectors                                                                                   
    +import pandas as pd
    +n = 10
    +x = np.random.normal(size=n)
     x = x - np.mean(x)
    +y = 4+3*x+np.random.normal(size=n)
     y = y - np.mean(y)
    -variance_x = np.sum(x@x)/n
    -variance_y = np.sum(y@y)/n
    -print(variance_x)
    -print(variance_y)
    -cov_xy = np.sum(x@y)/n
    -cov_xx = np.sum(x@x)/n
    -cov_yy = np.sum(y@y)/n
    -C = np.zeros((2,2))
    -C[0,0]= cov_xx/variance_x
    -C[1,1]= cov_yy/variance_y
    -C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
    -C[1,0]= C[0,1]
    -print(C)
    +# Note that we transpose the matrix in order to stay with our ordering n x p
    +X = (np.vstack((x, y))).T
    +print(X)
    +Xpd = pd.DataFrame(X)
    +print(Xpd)
    +correlation_matrix = Xpd.corr()
    +print(correlation_matrix)
     
    @@ -373,12 +358,6 @@ C[1,0]
    -

    We see that the matrix elements along the diagonal are one as they -should be and that the matrix is symmetric. Furthermore, diagonalizing -this matrix we easily see that it is a positive definite matrix. -

    - -

    The above procedure with numpy can be made more compact if we use pandas.

    @@ -403,7 +382,6 @@ this matrix we easily see that it is a positive definite matrix.

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs054.html b/doc/pub/week35/html/._week35-bs054.html index dc935c8e2..8e4a66991 100644 --- a/doc/pub/week35/html/._week35-bs054.html +++ b/doc/pub/week35/html/._week35-bs054.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,45 +319,41 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Matrix with Pandas

    +

    Rewriting the Covariance and/or Correlation Matrix

    -

    We whow here how we can set up the correlation matrix using pandas, as done in this simple code

    +

    We can rewrite the covariance matrix in a more compact form in terms of the design/feature matrix \( \boldsymbol{X} \) as

    +$$ +\boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}= \mathbb{E}[\boldsymbol{X}^T\boldsymbol{X}]. +$$ - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -n = 10
    -x = np.random.normal(size=n)
    -x = x - np.mean(x)
    -y = 4+3*x+np.random.normal(size=n)
    -y = y - np.mean(y)
    -# Note that we transpose the matrix in order to stay with our ordering n x p
    -X = (np.vstack((x, y))).T
    -print(X)
    -Xpd = pd.DataFrame(X)
    -print(Xpd)
    -correlation_matrix = Xpd.corr()
    -print(correlation_matrix)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    To see this let us simply look at a design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{2\times 2} \)

    +$$ +\boldsymbol{X}=\begin{bmatrix} +x_{00} & x_{01}\\ +x_{10} & x_{11}\\ +\end{bmatrix}=\begin{bmatrix} +\boldsymbol{x}_{0} & \boldsymbol{x}_{1}\\ +\end{bmatrix}. +$$ +

    If we then compute the expectation value (note the \( 1/n \) factor instead of \( 1/(n-1) \))

    +$$ +\mathbb{E}[\boldsymbol{X}^T\boldsymbol{X}] = \frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}=\frac{1}{n}\begin{bmatrix} +x_{00}^2+x_{10}^2 & x_{00}x_{01}+x_{10}x_{11}\\ +x_{01}x_{00}+x_{11}x_{10} & x_{01}^2+x_{11}^2\\ +\end{bmatrix}, +$$ + +

    which is just

    +$$ +\boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]=\begin{bmatrix} \mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] \\ + \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] \\ + \end{bmatrix}, +$$ + +

    where we wrote $$\boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]$$ to indicate that this is the covariance of the vectors \( \boldsymbol{x} \) of the design/feature matrix \( \boldsymbol{X} \).

    + +

    It is easy to generalize this to a matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \).

    @@ -383,7 +377,6 @@ correlation_matrix = Xpd60

  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs055.html b/doc/pub/week35/html/._week35-bs055.html index b1e81b768..b8a0ed473 100644 --- a/doc/pub/week35/html/._week35-bs055.html +++ b/doc/pub/week35/html/._week35-bs055.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,41 +319,39 @@ MathJax.Hub.Config({

     

     

     

    -

    Rewriting the Covariance and/or Correlation Matrix

    +

    Linking with the SVD

    -

    We can rewrite the covariance matrix in a more compact form in terms of the design/feature matrix \( \boldsymbol{X} \) as

    +

    We saw earlier that

    $$ -\boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}= \mathbb{E}[\boldsymbol{X}^T\boldsymbol{X}]. +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. $$ -

    To see this let us simply look at a design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{2\times 2} \)

    +

    Since the matrices here have dimension \( p\times p \), with \( p \) corresponding to the singular values, we defined earlier the matrix

    $$ -\boldsymbol{X}=\begin{bmatrix} -x_{00} & x_{01}\\ -x_{10} & x_{11}\\ -\end{bmatrix}=\begin{bmatrix} -\boldsymbol{x}_{0} & \boldsymbol{x}_{1}\\ -\end{bmatrix}. +\boldsymbol{\Sigma}^T\boldsymbol{\Sigma} = \begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \\ \boldsymbol{0}\\ \end{bmatrix}, $$ -

    If we then compute the expectation value (note the \( 1/n \) factor instead of \( 1/(n-1) \))

    +

    where the tilde-matrix \( \tilde{\boldsymbol{\Sigma}} \) is a matrix of dimension \( p\times p \) containing only the singular values \( \sigma_i \), that is

    + $$ -\mathbb{E}[\boldsymbol{X}^T\boldsymbol{X}] = \frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}=\frac{1}{n}\begin{bmatrix} -x_{00}^2+x_{10}^2 & x_{00}x_{01}+x_{10}x_{11}\\ -x_{01}x_{00}+x_{11}x_{10} & x_{01}^2+x_{11}^2\\ +\tilde{\boldsymbol{\Sigma}}=\begin{bmatrix} \sigma_0 & 0 & 0 & \dots & 0 & 0 \\ + 0 & \sigma_1 & 0 & \dots & 0 & 0 \\ + 0 & 0 & \sigma_2 & \dots & 0 & 0 \\ + 0 & 0 & 0 & \dots & \sigma_{p-2} & 0 \\ + 0 & 0 & 0 & \dots & 0 & \sigma_{p-1} \\ \end{bmatrix}, $$ -

    which is just

    +

    meaning we can write

    $$ -\boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]=\begin{bmatrix} \mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] \\ - \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] \\ - \end{bmatrix}, +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^2\boldsymbol{V}^T. $$ -

    where we wrote $$\boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]$$ to indicate that this is the covariance of the vectors \( \boldsymbol{x} \) of the design/feature matrix \( \boldsymbol{X} \).

    +

    Multiplying from the right with \( \boldsymbol{V} \) (using the orthogonality of \( \boldsymbol{V} \)) we get

    +$$ +\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{V}=\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^2. +$$ -

    It is easy to generalize this to a matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \).

    @@ -378,7 +374,6 @@ $$

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs056.html b/doc/pub/week35/html/._week35-bs056.html index 8377a34a2..fff321b7b 100644 --- a/doc/pub/week35/html/._week35-bs056.html +++ b/doc/pub/week35/html/._week35-bs056.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,39 +319,45 @@ MathJax.Hub.Config({

     

     

     

    -

    Linking with the SVD

    +

    What does it mean?

    -

    We saw earlier that

    -$$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. -$$ - -

    Since the matrices here have dimension \( p\times p \), with \( p \) corresponding to the singular values, we defined earlier the matrix

    -$$ -\boldsymbol{\Sigma}^T\boldsymbol{\Sigma} = \begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \\ \boldsymbol{0}\\ \end{bmatrix}, -$$ - -

    where the tilde-matrix \( \tilde{\boldsymbol{\Sigma}} \) is a matrix of dimension \( p\times p \) containing only the singular values \( \sigma_i \), that is

    +

    This means the vectors \( \boldsymbol{v}_i \) of the orthogonal matrix \( \boldsymbol{V} \) +are the eigenvectors of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) with eigenvalues +given by the singular values squared, that is +

    $$ -\tilde{\boldsymbol{\Sigma}}=\begin{bmatrix} \sigma_0 & 0 & 0 & \dots & 0 & 0 \\ - 0 & \sigma_1 & 0 & \dots & 0 & 0 \\ - 0 & 0 & \sigma_2 & \dots & 0 & 0 \\ - 0 & 0 & 0 & \dots & \sigma_{p-2} & 0 \\ - 0 & 0 & 0 & \dots & 0 & \sigma_{p-1} \\ -\end{bmatrix}, +\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. $$ -

    meaning we can write

    +

    In other words, each non-zero singular value of \( \boldsymbol{X} \) is a positive +square root of an eigenvalue of \( \boldsymbol{X}^T\boldsymbol{X} \). It means also that +the columns of \( \boldsymbol{V} \) are the eigenvectors of +\( \boldsymbol{X}^T\boldsymbol{X} \). Since we have ordered the singular values of +\( \boldsymbol{X} \) in a descending order, it means that the column vectors +\( \boldsymbol{v}_i \) are hierarchically ordered by how much correlation they +encode from the columns of \( \boldsymbol{X} \). +

    + +

    Note that these are also the eigenvectors and eigenvalues of the +Hessian matrix. Note also that the Hessian matrix we are discussing here is from a cost function defined by the mean squared error only. +

    + +

    If we now recall the definition of the covariance matrix (not using +Bessel's correction) we have +

    + $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^2\boldsymbol{V}^T. -$$ - -

    Multiplying from the right with \( \boldsymbol{V} \) (using the orthogonality of \( \boldsymbol{V} \)) we get

    -$$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{V}=\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^2. +\boldsymbol{C}[\boldsymbol{X}]=\frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}, $$ +

    meaning that every squared non-singular value of \( \boldsymbol{X} \) divided by \( n \) ( +the number of samples) are the eigenvalues of the covariance +matrix. Every singular value of \( \boldsymbol{X} \) is thus a positive square +root of an eigenvalue of \( \boldsymbol{X}^T\boldsymbol{X} \). If the matrix \( \boldsymbol{X} \) is +self-adjoint, the singular values of \( \boldsymbol{X} \) are equal to the +absolute value of the eigenvalues of \( \boldsymbol{X} \). +

    @@ -375,7 +379,6 @@ $$

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs057.html b/doc/pub/week35/html/._week35-bs057.html index d1024e3af..4895439fa 100644 --- a/doc/pub/week35/html/._week35-bs057.html +++ b/doc/pub/week35/html/._week35-bs057.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,44 +319,38 @@ MathJax.Hub.Config({

     

     

     

    -

    What does it mean?

    +

    And finally \( \boldsymbol{X}\boldsymbol{X}^T \)

    -

    This means the vectors \( \boldsymbol{v}_i \) of the orthogonal matrix \( \boldsymbol{V} \) -are the eigenvectors of the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) with eigenvalues -given by the singular values squared, that is -

    +

    For \( \boldsymbol{X}\boldsymbol{X}^T \) we found

    $$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. +\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T=\boldsymbol{U}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{U}^T. $$ -

    In other words, each non-zero singular value of \( \boldsymbol{X} \) is a positive -square root of an eigenvalue of \( \boldsymbol{X}^T\boldsymbol{X} \). It means also that -the columns of \( \boldsymbol{V} \) are the eigenvectors of -\( \boldsymbol{X}^T\boldsymbol{X} \). Since we have ordered the singular values of -\( \boldsymbol{X} \) in a descending order, it means that the column vectors -\( \boldsymbol{v}_i \) are hierarchically ordered by how much correlation they -encode from the columns of \( \boldsymbol{X} \). -

    - -

    Note that these are also the eigenvectors and eigenvalues of the -Hessian matrix. Note also that the Hessian matrix we are discussing here is from a cost function defined by the mean squared error only. -

    - -

    If we now recall the definition of the covariance matrix (not using -Bessel's correction) we have -

    - +

    Since the matrices here have dimension \( n\times n \), we have

    $$ -\boldsymbol{C}[\boldsymbol{X}]=\frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}, +\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T = \begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \\ \boldsymbol{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \boldsymbol{0}\\ \end{bmatrix}=\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}, $$ -

    meaning that every squared non-singular value of \( \boldsymbol{X} \) divided by \( n \) ( -the number of samples) are the eigenvalues of the covariance -matrix. Every singular value of \( \boldsymbol{X} \) is thus a positive square -root of an eigenvalue of \( \boldsymbol{X}^T\boldsymbol{X} \). If the matrix \( \boldsymbol{X} \) is -self-adjoint, the singular values of \( \boldsymbol{X} \) are equal to the -absolute value of the eigenvalues of \( \boldsymbol{X} \). +

    leading to

    +$$ +\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}\boldsymbol{U}^T. +$$ + +

    Multiplying with \( \boldsymbol{U} \) from the right gives us the eigenvalue problem

    +$$ +(\boldsymbol{X}\boldsymbol{X}^T)\boldsymbol{U}=\boldsymbol{U}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}. +$$ + +

    It means that the eigenvalues of \( \boldsymbol{X}\boldsymbol{X}^T \) are again given by +the non-zero singular values plus now a series of zeros. The column +vectors of \( \boldsymbol{U} \) are the eigenvectors of \( \boldsymbol{X}\boldsymbol{X}^T \) and +measure how much correlations are contained in the rows of \( \boldsymbol{X} \). +

    + +

    Since we will mainly be interested in the correlations among the features +of our data (the columns of \( \boldsymbol{X} \), the quantity of interest for us are the non-zero singular +values and the column vectors of \( \boldsymbol{V} \).

    @@ -380,7 +372,6 @@ absolute value of the eigenvalues of \( \boldsymbol{X} \).

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs058.html b/doc/pub/week35/html/._week35-bs058.html index 6e90d79ec..51ddfe207 100644 --- a/doc/pub/week35/html/._week35-bs058.html +++ b/doc/pub/week35/html/._week35-bs058.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,40 +319,81 @@ MathJax.Hub.Config({

     

     

     

    -

    And finally \( \boldsymbol{X}\boldsymbol{X}^T \)

    - -

    For \( \boldsymbol{X}\boldsymbol{X}^T \) we found

    +

    Back to Ridge and LASSO Regression

    +

    Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is +our optimization problem is +

    $$ -\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T=\boldsymbol{U}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{U}^T. +{\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$ -

    Since the matrices here have dimension \( n\times n \), we have

    +

    or we can state it as

    $$ -\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T = \begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \\ \boldsymbol{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \boldsymbol{0}\\ \end{bmatrix}=\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}, +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2, $$ -

    leading to

    +

    where we have used the definition of a norm-2 vector, that is

    $$ -\boldsymbol{X}\boldsymbol{X}^T=\boldsymbol{U}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}\boldsymbol{U}^T. +\vert\vert \boldsymbol{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}. $$ -

    Multiplying with \( \boldsymbol{U} \) from the right gives us the eigenvalue problem

    -$$ -(\boldsymbol{X}\boldsymbol{X}^T)\boldsymbol{U}=\boldsymbol{U}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0}\\ \end{bmatrix}. -$$ - -

    It means that the eigenvalues of \( \boldsymbol{X}\boldsymbol{X}^T \) are again given by -the non-zero singular values plus now a series of zeros. The column -vectors of \( \boldsymbol{U} \) are the eigenvectors of \( \boldsymbol{X}\boldsymbol{X}^T \) and -measure how much correlations are contained in the rows of \( \boldsymbol{X} \). +

    By minimizing the above equation with respect to the parameters +\( \boldsymbol{\theta} \) we could then obtain an analytical expression for the +parameters \( \boldsymbol{\theta} \). We can add a regularization parameter \( \lambda \) by +defining a new cost function to be optimized, that is

    -

    Since we will mainly be interested in the correlations among the features -of our data (the columns of \( \boldsymbol{X} \), the quantity of interest for us are the non-zero singular -values and the column vectors of \( \boldsymbol{V} \). +$$ +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_2^2 +$$ + +

    which leads to the Ridge regression minimization problem where we +require that \( \vert\vert \boldsymbol{\theta}\vert\vert_2^2\le t \), where \( t \) is +a finite number larger than zero. By defining

    +$$ +C(\boldsymbol{X},\boldsymbol{\theta})=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1, +$$ + +

    we have a new optimization equation

    +$$ +{\displaystyle \min_{\boldsymbol{\theta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1 +$$ + +

    which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.

    + +

    Here we have defined the norm-1 as

    +$$ +\vert\vert \boldsymbol{x}\vert\vert_1 = \sum_i \vert x_i\vert. +$$ + +

    Ridge regression, as discussed above, is nothing but the standard OLS with a +modified diagonal term added to \( \boldsymbol{X}^T\boldsymbol{X} \). The consequences, in +particular for our discussion of the bias-variance tradeoff are rather +interesting. We will see that for specific values of \( \lambda \), we may +even reduce the variance of the optimal parameters \( \boldsymbol{\theta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here. +

    + +

    Using our insights about the SVD of the design matrix \( \boldsymbol{X} \) +We have already analyzed the OLS solutions in terms of the eigenvectors (the columns) of the right singular value matrix \( \boldsymbol{U} \) as +

    +$$ +\tilde{\boldsymbol{y}}_{\mathrm{OLS}}=\boldsymbol{X}\boldsymbol{\theta} =\boldsymbol{U}\boldsymbol{U}^T\boldsymbol{y}. +$$ + +

    For Ridge regression this becomes

    + +$$ +\tilde{\boldsymbol{y}}_{\mathrm{Ridge}}=\boldsymbol{X}\boldsymbol{\theta}_{\mathrm{Ridge}} = \boldsymbol{U\Sigma V^T}\left(\boldsymbol{V}\boldsymbol{\Sigma}^2\boldsymbol{V}^T+\lambda\boldsymbol{I} \right)^{-1}(\boldsymbol{U\Sigma V^T})^T\boldsymbol{y}=\sum_{j=0}^{p-1}\boldsymbol{u}_j\boldsymbol{u}_j^T\frac{\sigma_j^2}{\sigma_j^2+\lambda}\boldsymbol{y}, +$$ + +

    with the vectors \( \boldsymbol{u}_j \) being the columns of \( \boldsymbol{U} \) from the SVD of the matrix \( \boldsymbol{X} \).

    +

      @@ -373,7 +412,6 @@ values and the column vectors of \( \boldsymbol{V} \).
    • 60
    • 61
    • 62
    • -
    • 63
    • »
    diff --git a/doc/pub/week35/html/._week35-bs059.html b/doc/pub/week35/html/._week35-bs059.html index b5da28212..c9826857c 100644 --- a/doc/pub/week35/html/._week35-bs059.html +++ b/doc/pub/week35/html/._week35-bs059.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,80 +319,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Back to Ridge and LASSO Regression

    +

    Interpreting the Ridge results

    + +

    Since \( \lambda \geq 0 \), it means that compared to OLS, we have

    -

    Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is -our optimization problem is -

    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. +\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1. $$ -

    or we can state it as

    -$$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2, -$$ - -

    where we have used the definition of a norm-2 vector, that is

    -$$ -\vert\vert \boldsymbol{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}. -$$ - -

    By minimizing the above equation with respect to the parameters -\( \boldsymbol{\theta} \) we could then obtain an analytical expression for the -parameters \( \boldsymbol{\theta} \). We can add a regularization parameter \( \lambda \) by -defining a new cost function to be optimized, that is +

    Ridge regression finds the coordinates of \( \boldsymbol{y} \) with respect to the +orthonormal basis \( \boldsymbol{U} \), it then shrinks the coordinates by +\( \frac{\sigma_j^2}{\sigma_j^2+\lambda} \). Recall that the SVD has +eigenvalues ordered in a descending way, that is \( \sigma_i \geq +\sigma_{i+1} \).

    -$$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_2^2 -$$ - -

    which leads to the Ridge regression minimization problem where we -require that \( \vert\vert \boldsymbol{\theta}\vert\vert_2^2\le t \), where \( t \) is -a finite number larger than zero. By defining -

    - -$$ -C(\boldsymbol{X},\boldsymbol{\theta})=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1, -$$ - -

    we have a new optimization equation

    -$$ -{\displaystyle \min_{\boldsymbol{\theta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\theta}\vert\vert_1 -$$ - -

    which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.

    - -

    Here we have defined the norm-1 as

    -$$ -\vert\vert \boldsymbol{x}\vert\vert_1 = \sum_i \vert x_i\vert. -$$ - -

    Ridge regression, as discussed above, is nothing but the standard OLS with a -modified diagonal term added to \( \boldsymbol{X}^T\boldsymbol{X} \). The consequences, in -particular for our discussion of the bias-variance tradeoff are rather -interesting. We will see that for specific values of \( \lambda \), we may -even reduce the variance of the optimal parameters \( \boldsymbol{\theta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here. -

    - -

    Using our insights about the SVD of the design matrix \( \boldsymbol{X} \) -We have already analyzed the OLS solutions in terms of the eigenvectors (the columns) of the right singular value matrix \( \boldsymbol{U} \) as -

    -$$ -\tilde{\boldsymbol{y}}_{\mathrm{OLS}}=\boldsymbol{X}\boldsymbol{\theta} =\boldsymbol{U}\boldsymbol{U}^T\boldsymbol{y}. -$$ - -

    For Ridge regression this becomes

    - -$$ -\tilde{\boldsymbol{y}}_{\mathrm{Ridge}}=\boldsymbol{X}\boldsymbol{\theta}_{\mathrm{Ridge}} = \boldsymbol{U\Sigma V^T}\left(\boldsymbol{V}\boldsymbol{\Sigma}^2\boldsymbol{V}^T+\lambda\boldsymbol{I} \right)^{-1}(\boldsymbol{U\Sigma V^T})^T\boldsymbol{y}=\sum_{j=0}^{p-1}\boldsymbol{u}_j\boldsymbol{u}_j^T\frac{\sigma_j^2}{\sigma_j^2+\lambda}\boldsymbol{y}, -$$ - -

    with the vectors \( \boldsymbol{u}_j \) being the columns of \( \boldsymbol{U} \) from the SVD of the matrix \( \boldsymbol{X} \).

    +

    For small eigenvalues \( \sigma_i \) it means that their contributions become less important, a fact which can be used to reduce the number of degrees of freedom. More about this when we have covered the material on a statistical interpretation of various linear regression methods.

    @@ -413,7 +353,6 @@ $$

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs060.html b/doc/pub/week35/html/._week35-bs060.html index 3173cf60c..1786f345c 100644 --- a/doc/pub/week35/html/._week35-bs060.html +++ b/doc/pub/week35/html/._week35-bs060.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,22 +319,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Interpreting the Ridge results

    +

    More interpretations

    -

    Since \( \lambda \geq 0 \), it means that compared to OLS, we have

    +

    For the sake of simplicity, let us assume that the design matrix is orthonormal, that is

    $$ -\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1. +\boldsymbol{X}^T\boldsymbol{X}=(\boldsymbol{X}^T\boldsymbol{X})^{-1} =\boldsymbol{I}. $$ -

    Ridge regression finds the coordinates of \( \boldsymbol{y} \) with respect to the -orthonormal basis \( \boldsymbol{U} \), it then shrinks the coordinates by -\( \frac{\sigma_j^2}{\sigma_j^2+\lambda} \). Recall that the SVD has -eigenvalues ordered in a descending way, that is \( \sigma_i \geq -\sigma_{i+1} \). +

    In this case the standard OLS results in

    +$$ +\boldsymbol{\theta}^{\mathrm{OLS}} = \boldsymbol{X}^T\boldsymbol{y}=\sum_{i=0}^{n-1}\boldsymbol{u}_i\boldsymbol{u}_i^T\boldsymbol{y}, +$$ + +

    and

    + +$$ +\boldsymbol{\theta}^{\mathrm{Ridge}} = \left(\boldsymbol{I}+\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}=\left(1+\lambda\right)^{-1}\boldsymbol{\theta}^{\mathrm{OLS}}, +$$ + +

    that is the Ridge estimator scales the OLS estimator by the inverse of a factor \( 1+\lambda \), and +the Ridge estimator converges to zero when the hyperparameter goes to +infinity.

    -

    For small eigenvalues \( \sigma_i \) it means that their contributions become less important, a fact which can be used to reduce the number of degrees of freedom. More about this when we have covered the material on a statistical interpretation of various linear regression methods.

    +

    We will come back to more interpreations after we have gone through some of the statistical analysis part.

    + +

    For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. +Similarly, Mehta et al's article is also recommended. +

    @@ -354,7 +365,6 @@ eigenvalues ordered in a descending way, that is \( \sigma_i \geq

  • 60
  • 61
  • 62
  • -
  • 63
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs061.html b/doc/pub/week35/html/._week35-bs061.html index a43bc8a76..8b084197b 100644 --- a/doc/pub/week35/html/._week35-bs061.html +++ b/doc/pub/week35/html/._week35-bs061.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -321,35 +319,36 @@ MathJax.Hub.Config({

     

     

     

    -

    More interpretations

    +

    Deriving the Lasso Regression Equations

    -

    For the sake of simplicity, let us assume that the design matrix is orthonormal, that is

    +

    Using the matrix-vector expression for Lasso regression, we have the following cost function

    $$ -\boldsymbol{X}^T\boldsymbol{X}=(\boldsymbol{X}^T\boldsymbol{X})^{-1} =\boldsymbol{I}. +C(\boldsymbol{X},\boldsymbol{\theta})=\frac{1}{n}\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})\right\}+\lambda\vert\vert\boldsymbol{\theta}\vert\vert_1, $$ -

    In this case the standard OLS results in

    +

    Taking the derivative with respect to \( \boldsymbol{\theta} \) and recalling that the derivative of the absolute value is (we drop the boldfaced vector symbol for simplicty)

    $$ -\boldsymbol{\theta}^{\mathrm{OLS}} = \boldsymbol{X}^T\boldsymbol{y}=\sum_{i=0}^{n-1}\boldsymbol{u}_i\boldsymbol{u}_i^T\boldsymbol{y}, +\frac{d \vert \theta\vert}{d \theta}=\mathrm{sgn}(\theta)=\left\{\begin{array}{cc} 1 & \theta > 0 \\-1 & \theta < 0, \end{array}\right. $$ -

    and

    +

    we have that the derivative of the cost function is

    $$ -\boldsymbol{\theta}^{\mathrm{Ridge}} = \left(\boldsymbol{I}+\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}=\left(1+\lambda\right)^{-1}\boldsymbol{\theta}^{\mathrm{OLS}}, +\frac{\partial C(\boldsymbol{X},\boldsymbol{\theta})}{\partial \boldsymbol{\theta}}=-\frac{2}{n}\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta})+\lambda sgn(\boldsymbol{\theta})=0, $$ -

    that is the Ridge estimator scales the OLS estimator by the inverse of a factor \( 1+\lambda \), and -the Ridge estimator converges to zero when the hyperparameter goes to -infinity. -

    +

    and reordering we have

    +$$ +\boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta}+\frac{n}{2}\lambda sgn(\boldsymbol{\theta})=2\boldsymbol{X}^T\boldsymbol{y}. +$$ -

    We will come back to more interpreations after we have gone through some of the statistical analysis part.

    +

    We can redefine \( \lambda \) to absorb the constant \( n/2 \) and we rewrite the last equation as

    +$$ +\boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta}+\lambda sgn(\boldsymbol{\theta})=2\boldsymbol{X}^T\boldsymbol{y}. +$$ -

    For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. -Similarly, Mehta et al's article is also recommended. -

    +

    This equation does not lead to a nice analytical equation as in either Ridge regression or ordinary least squares. This equation can however be solved by using standard convex optimization algorithms using for example the Python package CVXOPT. We will discuss how to code LASSO regression next week, when we have introduced gradient methods.

    @@ -366,8 +365,6 @@ Similarly, Mehta et al

  • 60
  • 61
  • 62
  • -
  • 63
  • -
  • »
  • diff --git a/doc/pub/week35/html/week35-bs.html b/doc/pub/week35/html/week35-bs.html index badf47a47..028edad4c 100644 --- a/doc/pub/week35/html/week35-bs.html +++ b/doc/pub/week35/html/week35-bs.html @@ -65,7 +65,6 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -252,8 +251,8 @@ MathJax.Hub.Config({
  • Reminder from last week
  • The equations for ordinary least squares
  • The cost/loss function
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • The Jacobian
  • Derivatives, example 1
  • @@ -261,55 +260,54 @@ MathJax.Hub.Config({
  • Example 3
  • Example 4
  • The mean squared error and its derivative
  • -
  • Other useful relations
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Example relevant for the exercises
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • The complete code with a simple data set
  • -
  • Making your own test-train splitting
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Note about SVD Calculations
  • -
  • Mathematics of the SVD and implications
  • -
  • Example Matrix
  • -
  • Setting up the Matrix to be inverted
  • -
  • Further properties (important for our analyses later)
  • -
  • Meet the Covariance Matrix
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Covariance and Correlation Matrix
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Back to Ridge and LASSO Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Example relevant for the exercises
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • The complete code with a simple data set
  • +
  • Making your own test-train splitting
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematics of the SVD and implications
  • +
  • Example Matrix
  • +
  • Setting up the Matrix to be inverted
  • +
  • Further properties (important for our analyses later)
  • +
  • Meet the Covariance Matrix
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Covariance and Correlation Matrix
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Back to Ridge and LASSO Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • @@ -361,7 +359,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 63
  • +
  • 62
  • »
  • diff --git a/doc/pub/week35/html/week35-reveal.html b/doc/pub/week35/html/week35-reveal.html index 0ee0edad8..1e819dcec 100644 --- a/doc/pub/week35/html/week35-reveal.html +++ b/doc/pub/week35/html/week35-reveal.html @@ -353,7 +353,7 @@ will treat \( y_i \) as our exact value for the output variable.

    In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem

     
    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in +\hat{\boldsymbol{\theta}}={\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$

     
    @@ -402,7 +402,7 @@ $$

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

     
    $$ -\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +\hat{\boldsymbol{\theta}} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$

     
    @@ -414,7 +414,7 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). This is discussed on Thursday this week. +\( \boldsymbol{X}^T\boldsymbol{X} \).

    @@ -422,7 +422,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi

    -

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    +

    Small question: When inverting the matrix $\boldsymbol{X}^T\boldsymbol{X}, what kind of problems can we expect?

    @@ -709,35 +709,6 @@ $$

     
    -

    -

    Other useful relations

    - -

    We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters)

    -

     
    -$$ -\frac{\partial (\boldsymbol{x}^T\boldsymbol{a})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ -

     
    - -

     
    -$$ -\frac{\partial (\boldsymbol{a}^T\boldsymbol{x})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ -

     
    - -

     
    -$$ -\frac{\partial tr(\boldsymbol{B}\boldsymbol{A})}{\partial \boldsymbol{A}} = \boldsymbol{B}^T, -$$ -

     
    - -

     
    -$$ -\frac{\partial \log{\vert\boldsymbol{A}\vert}}{\partial \boldsymbol{A}} = (\boldsymbol{A}^{-1})^T. -$$ -

     
    -

    -

    Meet the Hessian Matrix

    @@ -764,11 +735,11 @@ $$

    For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters -\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see later this week that it is +\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see next week that it is (aside the factor \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning/data analysis -problem. +problem. We will discuss this in greater detail next week when we introduce gradient methods.

    Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).

    diff --git a/doc/pub/week35/html/week35-solarized.html b/doc/pub/week35/html/week35-solarized.html index a025f23f0..ae4055a7f 100644 --- a/doc/pub/week35/html/week35-solarized.html +++ b/doc/pub/week35/html/week35-solarized.html @@ -92,7 +92,6 @@ div.toc p,a { 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -416,7 +415,7 @@ will treat \( y_i \) as our exact value for the output variable.

    In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem

    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in +\hat{\boldsymbol{\theta}}={\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$ @@ -453,7 +452,7 @@ $$

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ -\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +\hat{\boldsymbol{\theta}} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in @@ -464,7 +463,7 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). This is discussed on Thursday this week. +\( \boldsymbol{X}^T\boldsymbol{X} \).

    @@ -472,7 +471,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi

    -

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    +

    Small question: When inverting the matrix $\boldsymbol{X}^T\boldsymbol{X}, what kind of problems can we expect?

    @@ -704,28 +703,6 @@ $$ $$ -









    -

    Other useful relations

    - -

    We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters)

    -$$ -\frac{\partial (\boldsymbol{x}^T\boldsymbol{a})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ - -$$ -\frac{\partial (\boldsymbol{a}^T\boldsymbol{x})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ - - -$$ -\frac{\partial tr(\boldsymbol{B}\boldsymbol{A})}{\partial \boldsymbol{A}} = \boldsymbol{B}^T, -$$ - -$$ -\frac{\partial \log{\vert\boldsymbol{A}\vert}}{\partial \boldsymbol{A}} = (\boldsymbol{A}^{-1})^T. -$$ - -









    Meet the Hessian Matrix

    @@ -748,11 +725,11 @@ $$

    For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters -\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see later this week that it is +\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see next week that it is (aside the factor \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning/data analysis -problem. +problem. We will discuss this in greater detail next week when we introduce gradient methods.

    Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).

    diff --git a/doc/pub/week35/html/week35.html b/doc/pub/week35/html/week35.html index 94bc64f42..d2cce1874 100644 --- a/doc/pub/week35/html/week35.html +++ b/doc/pub/week35/html/week35.html @@ -169,7 +169,6 @@ div.toc p,a { 2, None, 'the-mean-squared-error-and-its-derivative'), - ('Other useful relations', 2, None, 'other-useful-relations'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -493,7 +492,7 @@ will treat \( y_i \) as our exact value for the output variable.

    In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem

    $$ -{\displaystyle \min_{\boldsymbol{\theta}\in +\hat{\boldsymbol{\theta}}={\displaystyle \min_{\boldsymbol{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. $$ @@ -530,7 +529,7 @@ $$

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ -\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. +\hat{\boldsymbol{\theta}} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in @@ -541,7 +540,7 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). This is discussed on Thursday this week. +\( \boldsymbol{X}^T\boldsymbol{X} \).

    @@ -549,7 +548,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi

    -

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    +

    Small question: When inverting the matrix $\boldsymbol{X}^T\boldsymbol{X}, what kind of problems can we expect?

    @@ -781,28 +780,6 @@ $$ $$ -









    -

    Other useful relations

    - -

    We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters)

    -$$ -\frac{\partial (\boldsymbol{x}^T\boldsymbol{a})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ - -$$ -\frac{\partial (\boldsymbol{a}^T\boldsymbol{x})}{\partial \boldsymbol{x}} = \boldsymbol{a}^T, -$$ - - -$$ -\frac{\partial tr(\boldsymbol{B}\boldsymbol{A})}{\partial \boldsymbol{A}} = \boldsymbol{B}^T, -$$ - -$$ -\frac{\partial \log{\vert\boldsymbol{A}\vert}}{\partial \boldsymbol{A}} = (\boldsymbol{A}^{-1})^T. -$$ - -









    Meet the Hessian Matrix

    @@ -825,11 +802,11 @@ $$

    For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters -\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see later this week that it is +\( \hat{\boldsymbol{\theta}} \). Furthermore, we will see next week that it is (aside the factor \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning/data analysis -problem. +problem. We will discuss this in greater detail next week when we introduce gradient methods.

    Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).

    diff --git a/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz b/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz index ffbffda8a004ffd9363b4074d504d6fd4234e8e6..21143a638ae66a497019b42d5b560b206641eb00 100644 GIT binary patch delta 158 zcmV;P0Ac^Y0l)zqABzY8BKNCk00ZsM%?iRW3|Wemp5Qa&X~ z=6Vvx9AZv*l4X>!1V~IdWdV@oPI~FA6J|K2sm`b@s&{k4SXqA9Grt1Q{1eAYTG;M; zS7`-GJIuAN;f7dK9?7;>ITRZ0*aCysP8tNEdJsh+ozzNP!q(`M5si()Uq9n{p67k- M0Tlo{_5cU~0J^_MZ~y=R delta 158 zcmV;P0Ac^Y0l)zqABzY8I`pe(00ZsM%?iRW3|OH&w=XKYGB z=Xw&y3}QwY<(v{ufy4<*XaHonlU_ROgc(k0sxvB!>fPKhR+b<3%&)*R|HQG97PkA| zRa$}44s)$*xFOaFi)7oY914wgY=OaRCk=v7J&2-^PHH7CVQcish{i_Yub=Te&-1?a M0F;{%%>W1h0JG3YXaE2J diff --git a/doc/pub/week35/ipynb/week35.ipynb b/doc/pub/week35/ipynb/week35.ipynb index 758268d50..35f134d71 100644 --- a/doc/pub/week35/ipynb/week35.ipynb +++ b/doc/pub/week35/ipynb/week35.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "fe6b2c85", + "id": "82c2f725", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "dda0831e", + "id": "d2fc786b", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "3846244e", + "id": "77512f33", "metadata": { "editable": true }, @@ -49,7 +49,7 @@ }, { "cell_type": "markdown", - "id": "5429bb07", + "id": "41516757", "metadata": { "editable": true }, @@ -69,7 +69,7 @@ }, { "cell_type": "markdown", - "id": "12cb8a51", + "id": "d3703d2f", "metadata": { "editable": true }, @@ -102,7 +102,7 @@ }, { "cell_type": "markdown", - "id": "6fa8f9ec", + "id": "f22b90af", "metadata": { "editable": true }, @@ -118,7 +118,7 @@ }, { "cell_type": "markdown", - "id": "127fc634", + "id": "3fe305bb", "metadata": { "editable": true }, @@ -130,7 +130,7 @@ }, { "cell_type": "markdown", - "id": "9a8acf0d", + "id": "f2f38355", "metadata": { "editable": true }, @@ -140,7 +140,7 @@ }, { "cell_type": "markdown", - "id": "65f1aeba", + "id": "c3d9a4b6", "metadata": { "editable": true }, @@ -152,7 +152,7 @@ }, { "cell_type": "markdown", - "id": "597cbf98", + "id": "ff3ba043", "metadata": { "editable": true }, @@ -173,7 +173,7 @@ }, { "cell_type": "markdown", - "id": "d41f8f1d", + "id": "5de294d5", "metadata": { "editable": true }, @@ -185,7 +185,7 @@ }, { "cell_type": "markdown", - "id": "a8af8260", + "id": "5721942a", "metadata": { "editable": true }, @@ -198,7 +198,7 @@ }, { "cell_type": "markdown", - "id": "977b8e6a", + "id": "2b2aa843", "metadata": { "editable": true }, @@ -210,7 +210,7 @@ }, { "cell_type": "markdown", - "id": "4b1ea940", + "id": "2b12c06f", "metadata": { "editable": true }, @@ -222,7 +222,7 @@ }, { "cell_type": "markdown", - "id": "f01ebb5f", + "id": "276d4eba", "metadata": { "editable": true }, @@ -232,7 +232,7 @@ }, { "cell_type": "markdown", - "id": "9907305e", + "id": "4751c9b4", "metadata": { "editable": true }, @@ -244,7 +244,7 @@ }, { "cell_type": "markdown", - "id": "f97935af", + "id": "dd00bf4b", "metadata": { "editable": true }, @@ -257,7 +257,7 @@ }, { "cell_type": "markdown", - "id": "5c92b4f0", + "id": "bc9028f0", "metadata": { "editable": true }, @@ -269,7 +269,7 @@ }, { "cell_type": "markdown", - "id": "2d544181", + "id": "d6a27e54", "metadata": { "editable": true }, @@ -279,7 +279,7 @@ }, { "cell_type": "markdown", - "id": "2cf50723", + "id": "82f1494a", "metadata": { "editable": true }, @@ -291,7 +291,7 @@ }, { "cell_type": "markdown", - "id": "39be0901", + "id": "d6427a35", "metadata": { "editable": true }, @@ -303,7 +303,7 @@ }, { "cell_type": "markdown", - "id": "5c917e58", + "id": "38c78421", "metadata": { "editable": true }, @@ -314,7 +314,7 @@ }, { "cell_type": "markdown", - "id": "03f79b85", + "id": "f23ac12e", "metadata": { "editable": true }, @@ -326,7 +326,7 @@ }, { "cell_type": "markdown", - "id": "50feea96", + "id": "88fd9c03", "metadata": { "editable": true }, @@ -345,20 +345,20 @@ }, { "cell_type": "markdown", - "id": "6d7b7754", + "id": "a953b1a3", "metadata": { "editable": true }, "source": [ "$$\n", - "{\\displaystyle \\min_{\\boldsymbol{\\theta}\\in\n", + "\\hat{\\boldsymbol{\\theta}}={\\displaystyle \\min_{\\boldsymbol{\\theta}\\in\n", "{\\mathbb{R}}^{p}}}\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)\\right\\}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "5740e059", + "id": "19eb0838", "metadata": { "editable": true }, @@ -368,7 +368,7 @@ }, { "cell_type": "markdown", - "id": "82b02a85", + "id": "a4f910a4", "metadata": { "editable": true }, @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "7a9d780a", + "id": "5060e089", "metadata": { "editable": true }, @@ -390,7 +390,7 @@ }, { "cell_type": "markdown", - "id": "1bdfd08f", + "id": "8542c5a3", "metadata": { "editable": true }, @@ -402,7 +402,7 @@ }, { "cell_type": "markdown", - "id": "7a6c1fe3", + "id": "475e1436", "metadata": { "editable": true }, @@ -412,7 +412,7 @@ }, { "cell_type": "markdown", - "id": "ef9b36ea", + "id": "88abf4ad", "metadata": { "editable": true }, @@ -424,7 +424,7 @@ }, { "cell_type": "markdown", - "id": "87287063", + "id": "62f558d9", "metadata": { "editable": true }, @@ -435,7 +435,7 @@ }, { "cell_type": "markdown", - "id": "18fea54e", + "id": "99cc5104", "metadata": { "editable": true }, @@ -447,7 +447,7 @@ }, { "cell_type": "markdown", - "id": "02d1cb9b", + "id": "29043759", "metadata": { "editable": true }, @@ -457,7 +457,7 @@ }, { "cell_type": "markdown", - "id": "a7a8c150", + "id": "e9d0f067", "metadata": { "editable": true }, @@ -469,7 +469,7 @@ }, { "cell_type": "markdown", - "id": "c4a6f56f", + "id": "c34bfdd2", "metadata": { "editable": true }, @@ -479,19 +479,19 @@ }, { "cell_type": "markdown", - "id": "bba7e66b", + "id": "3533f92e", "metadata": { "editable": true }, "source": [ "$$\n", - "\\boldsymbol{\\theta} =\\left(\\boldsymbol{X}^T\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^T\\boldsymbol{y}.\n", + "\\hat{\\boldsymbol{\\theta}} =\\left(\\boldsymbol{X}^T\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^T\\boldsymbol{y}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "e0896056", + "id": "135631d4", "metadata": { "editable": true }, @@ -504,14 +504,14 @@ "supervised learning algorithms like classification with logistic\n", "regression or support vector machines, exhibit dimensionalities which\n", "allow for the usage of direct linear algebra methods such as **LU** decomposition or **Singular Value Decomposition** (SVD) for finding the inverse of the matrix\n", - "$\\boldsymbol{X}^T\\boldsymbol{X}$. This is discussed on Thursday this week.\n", + "$\\boldsymbol{X}^T\\boldsymbol{X}$.\n", "\n", - "**Small question**: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix $\\boldsymbol{X}^T\\boldsymbol{X}$? What kind of problems can we expect?" + "**Small question**: When inverting the matrix $\\boldsymbol{X}^T\\boldsymbol{X}, what kind of problems can we expect?" ] }, { "cell_type": "markdown", - "id": "29256395", + "id": "cf25f4a7", "metadata": { "editable": true }, @@ -538,7 +538,7 @@ }, { "cell_type": "markdown", - "id": "4b2eab57", + "id": "5d82400a", "metadata": { "editable": true }, @@ -550,7 +550,7 @@ }, { "cell_type": "markdown", - "id": "50b13fd4", + "id": "00d8d123", "metadata": { "editable": true }, @@ -562,7 +562,7 @@ }, { "cell_type": "markdown", - "id": "42655d07", + "id": "cce17e14", "metadata": { "editable": true }, @@ -578,7 +578,7 @@ }, { "cell_type": "markdown", - "id": "9814790f", + "id": "65efb775", "metadata": { "editable": true }, @@ -596,7 +596,7 @@ }, { "cell_type": "markdown", - "id": "512e4d9d", + "id": "2df9efd6", "metadata": { "editable": true }, @@ -608,7 +608,7 @@ }, { "cell_type": "markdown", - "id": "e1760622", + "id": "37b621d8", "metadata": { "editable": true }, @@ -620,7 +620,7 @@ }, { "cell_type": "markdown", - "id": "379ff11c", + "id": "297be9c9", "metadata": { "editable": true }, @@ -631,7 +631,7 @@ }, { "cell_type": "markdown", - "id": "5896374a", + "id": "fe288c99", "metadata": { "editable": true }, @@ -643,7 +643,7 @@ }, { "cell_type": "markdown", - "id": "f401b6b1", + "id": "d4333779", "metadata": { "editable": true }, @@ -653,7 +653,7 @@ }, { "cell_type": "markdown", - "id": "5c9ca7a7", + "id": "f7e72c3d", "metadata": { "editable": true }, @@ -665,7 +665,7 @@ }, { "cell_type": "markdown", - "id": "4ddef016", + "id": "3423b702", "metadata": { "editable": true }, @@ -679,7 +679,7 @@ }, { "cell_type": "markdown", - "id": "7ac544c3", + "id": "fe66f713", "metadata": { "editable": true }, @@ -691,7 +691,7 @@ }, { "cell_type": "markdown", - "id": "5ee1a031", + "id": "43eed51b", "metadata": { "editable": true }, @@ -703,7 +703,7 @@ }, { "cell_type": "markdown", - "id": "2141e8a6", + "id": "6f943ccb", "metadata": { "editable": true }, @@ -715,7 +715,7 @@ }, { "cell_type": "markdown", - "id": "4bd967db", + "id": "5df09c55", "metadata": { "editable": true }, @@ -725,7 +725,7 @@ }, { "cell_type": "markdown", - "id": "a9143cdf", + "id": "b92d9f2a", "metadata": { "editable": true }, @@ -737,7 +737,7 @@ }, { "cell_type": "markdown", - "id": "96aa32a7", + "id": "c6cf49ab", "metadata": { "editable": true }, @@ -749,7 +749,7 @@ }, { "cell_type": "markdown", - "id": "648fe33d", + "id": "3e000448", "metadata": { "editable": true }, @@ -761,7 +761,7 @@ }, { "cell_type": "markdown", - "id": "d79b5251", + "id": "fbaa984b", "metadata": { "editable": true }, @@ -775,7 +775,7 @@ }, { "cell_type": "markdown", - "id": "c88a25e0", + "id": "f4e444ea", "metadata": { "editable": true }, @@ -787,7 +787,7 @@ }, { "cell_type": "markdown", - "id": "89700f18", + "id": "454ba5ba", "metadata": { "editable": true }, @@ -799,7 +799,7 @@ }, { "cell_type": "markdown", - "id": "b64f38e8", + "id": "c0434cd9", "metadata": { "editable": true }, @@ -811,7 +811,7 @@ }, { "cell_type": "markdown", - "id": "d5646c67", + "id": "f2bcda9d", "metadata": { "editable": true }, @@ -821,7 +821,7 @@ }, { "cell_type": "markdown", - "id": "84df0a05", + "id": "aea0ba73", "metadata": { "editable": true }, @@ -833,7 +833,7 @@ }, { "cell_type": "markdown", - "id": "8f5f956b", + "id": "5a58d6e8", "metadata": { "editable": true }, @@ -843,7 +843,7 @@ }, { "cell_type": "markdown", - "id": "e1edf078", + "id": "927428aa", "metadata": { "editable": true }, @@ -855,7 +855,7 @@ }, { "cell_type": "markdown", - "id": "bb92cb46", + "id": "372ad443", "metadata": { "editable": true }, @@ -865,7 +865,7 @@ }, { "cell_type": "markdown", - "id": "7f32b074", + "id": "37a99489", "metadata": { "editable": true }, @@ -877,7 +877,7 @@ }, { "cell_type": "markdown", - "id": "3de83250", + "id": "4872a1cd", "metadata": { "editable": true }, @@ -889,7 +889,7 @@ }, { "cell_type": "markdown", - "id": "fb5b37f4", + "id": "b21e9cb2", "metadata": { "editable": true }, @@ -901,7 +901,7 @@ }, { "cell_type": "markdown", - "id": "95088730", + "id": "442375d1", "metadata": { "editable": true }, @@ -916,7 +916,7 @@ }, { "cell_type": "markdown", - "id": "346e1e01", + "id": "aabab237", "metadata": { "editable": true }, @@ -928,7 +928,7 @@ }, { "cell_type": "markdown", - "id": "75cc8adf", + "id": "106f09df", "metadata": { "editable": true }, @@ -938,7 +938,7 @@ }, { "cell_type": "markdown", - "id": "7240fbf7", + "id": "73d8f824", "metadata": { "editable": true }, @@ -950,7 +950,7 @@ }, { "cell_type": "markdown", - "id": "45739ac5", + "id": "f2626be7", "metadata": { "editable": true }, @@ -960,7 +960,7 @@ }, { "cell_type": "markdown", - "id": "9cfb7b8b", + "id": "81d89d86", "metadata": { "editable": true }, @@ -972,7 +972,7 @@ }, { "cell_type": "markdown", - "id": "47f271c4", + "id": "59c2576a", "metadata": { "editable": true }, @@ -982,7 +982,7 @@ }, { "cell_type": "markdown", - "id": "9e43c0eb", + "id": "4b7bf3f9", "metadata": { "editable": true }, @@ -994,7 +994,7 @@ }, { "cell_type": "markdown", - "id": "73a1b664", + "id": "ea1e8943", "metadata": { "editable": true }, @@ -1006,7 +1006,7 @@ }, { "cell_type": "markdown", - "id": "13ff0a37", + "id": "d0425d72", "metadata": { "editable": true }, @@ -1018,7 +1018,7 @@ }, { "cell_type": "markdown", - "id": "f65f97cd", + "id": "38386834", "metadata": { "editable": true }, @@ -1028,7 +1028,7 @@ }, { "cell_type": "markdown", - "id": "462bdd9d", + "id": "bfbc4bd3", "metadata": { "editable": true }, @@ -1040,7 +1040,7 @@ }, { "cell_type": "markdown", - "id": "75cd2b5f", + "id": "3ced3cec", "metadata": { "editable": true }, @@ -1053,7 +1053,7 @@ }, { "cell_type": "markdown", - "id": "8c4628ac", + "id": "fc6f1dec", "metadata": { "editable": true }, @@ -1065,7 +1065,7 @@ }, { "cell_type": "markdown", - "id": "e4895b3c", + "id": "699662d2", "metadata": { "editable": true }, @@ -1075,7 +1075,7 @@ }, { "cell_type": "markdown", - "id": "6faee1d3", + "id": "0991592c", "metadata": { "editable": true }, @@ -1087,7 +1087,7 @@ }, { "cell_type": "markdown", - "id": "a9db6a82", + "id": "450dd961", "metadata": { "editable": true }, @@ -1097,7 +1097,7 @@ }, { "cell_type": "markdown", - "id": "032d2391", + "id": "a13de0fa", "metadata": { "editable": true }, @@ -1109,7 +1109,7 @@ }, { "cell_type": "markdown", - "id": "8f4f4bd4", + "id": "c64bc916", "metadata": { "editable": true }, @@ -1119,7 +1119,7 @@ }, { "cell_type": "markdown", - "id": "3182b446", + "id": "ab1e18bc", "metadata": { "editable": true }, @@ -1131,7 +1131,7 @@ }, { "cell_type": "markdown", - "id": "022fc455", + "id": "f1e74f34", "metadata": { "editable": true }, @@ -1141,7 +1141,7 @@ }, { "cell_type": "markdown", - "id": "e569bb86", + "id": "1ad3ebd9", "metadata": { "editable": true }, @@ -1153,7 +1153,7 @@ }, { "cell_type": "markdown", - "id": "55704805", + "id": "37d1b4ca", "metadata": { "editable": true }, @@ -1163,7 +1163,7 @@ }, { "cell_type": "markdown", - "id": "b201994d", + "id": "3d5fc67a", "metadata": { "editable": true }, @@ -1175,67 +1175,7 @@ }, { "cell_type": "markdown", - "id": "6dd614c7", - "metadata": { - "editable": true - }, - "source": [ - "## Other useful relations\n", - "\n", - "We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters)" - ] - }, - { - "cell_type": "markdown", - "id": "56e81476", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial (\\boldsymbol{x}^T\\boldsymbol{a})}{\\partial \\boldsymbol{x}} = \\boldsymbol{a}^T,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "de97ebef", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial (\\boldsymbol{a}^T\\boldsymbol{x})}{\\partial \\boldsymbol{x}} = \\boldsymbol{a}^T,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "a1991d16", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial tr(\\boldsymbol{B}\\boldsymbol{A})}{\\partial \\boldsymbol{A}} = \\boldsymbol{B}^T,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "75672f79", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial \\log{\\vert\\boldsymbol{A}\\vert}}{\\partial \\boldsymbol{A}} = (\\boldsymbol{A}^{-1})^T.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "377f7595", + "id": "d98472d9", "metadata": { "editable": true }, @@ -1251,7 +1191,7 @@ }, { "cell_type": "markdown", - "id": "0317807d", + "id": "5d859f20", "metadata": { "editable": true }, @@ -1263,7 +1203,7 @@ }, { "cell_type": "markdown", - "id": "95e55ee3", + "id": "e7bb91ec", "metadata": { "editable": true }, @@ -1273,7 +1213,7 @@ }, { "cell_type": "markdown", - "id": "abfbc048", + "id": "1553864b", "metadata": { "editable": true }, @@ -1285,25 +1225,25 @@ }, { "cell_type": "markdown", - "id": "cb332dcf", + "id": "f8cc9c71", "metadata": { "editable": true }, "source": [ "For ordinary least squares, it is inversely proportional (derivation\n", "next week) with the variance of the optimal parameters\n", - "$\\hat{\\boldsymbol{\\theta}}$. Furthermore, we will see later this week that it is\n", + "$\\hat{\\boldsymbol{\\theta}}$. Furthermore, we will see next week that it is\n", "(aside the factor $1/n$) equal to the covariance matrix. It plays also a very\n", "important role in optmization algorithms and Principal Component\n", "Analysis as a way to reduce the dimensionality of a machine learning/data analysis\n", - "problem.\n", + "problem. We will discuss this in greater detail next week when we introduce gradient methods.\n", "\n", "**Linear algebra question:** Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!)." ] }, { "cell_type": "markdown", - "id": "c06c73f8", + "id": "f1f01477", "metadata": { "editable": true }, @@ -1315,7 +1255,7 @@ }, { "cell_type": "markdown", - "id": "5ad43b2e", + "id": "f2dea7e1", "metadata": { "editable": true }, @@ -1327,7 +1267,7 @@ }, { "cell_type": "markdown", - "id": "26a6d0b3", + "id": "76b0f99e", "metadata": { "editable": true }, @@ -1337,7 +1277,7 @@ }, { "cell_type": "markdown", - "id": "f1fc4a69", + "id": "cfa3ca25", "metadata": { "editable": true }, @@ -1349,7 +1289,7 @@ }, { "cell_type": "markdown", - "id": "00d7ed1f", + "id": "9a9163d8", "metadata": { "editable": true }, @@ -1359,7 +1299,7 @@ }, { "cell_type": "markdown", - "id": "6b6a2df5", + "id": "c6b54a1e", "metadata": { "editable": true }, @@ -1371,7 +1311,7 @@ }, { "cell_type": "markdown", - "id": "5e20fc01", + "id": "659c98d0", "metadata": { "editable": true }, @@ -1381,7 +1321,7 @@ }, { "cell_type": "markdown", - "id": "562639e2", + "id": "209b5b37", "metadata": { "editable": true }, @@ -1395,7 +1335,7 @@ }, { "cell_type": "markdown", - "id": "78e5741a", + "id": "b325d0c3", "metadata": { "editable": true }, @@ -1407,7 +1347,7 @@ }, { "cell_type": "markdown", - "id": "533ac727", + "id": "c49a2fcd", "metadata": { "editable": true }, @@ -1418,7 +1358,7 @@ }, { "cell_type": "markdown", - "id": "2cf385db", + "id": "6978ef70", "metadata": { "editable": true }, @@ -1431,7 +1371,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "efc40f37", + "id": "01530c39", "metadata": { "collapsed": false, "editable": true @@ -1458,7 +1398,7 @@ }, { "cell_type": "markdown", - "id": "1ca86f2c", + "id": "90ff28d4", "metadata": { "editable": true }, @@ -1469,7 +1409,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "3fa40f13", + "id": "1d052cbe", "metadata": { "collapsed": false, "editable": true @@ -1482,7 +1422,7 @@ }, { "cell_type": "markdown", - "id": "10e10291", + "id": "3362efd4", "metadata": { "editable": true }, @@ -1496,7 +1436,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "50c7f127", + "id": "3e9e681f", "metadata": { "collapsed": false, "editable": true @@ -1509,7 +1449,7 @@ }, { "cell_type": "markdown", - "id": "9c565084", + "id": "78e4427f", "metadata": { "editable": true }, @@ -1520,7 +1460,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "b47323b9", + "id": "20aab659", "metadata": { "collapsed": false, "editable": true @@ -1532,7 +1472,7 @@ }, { "cell_type": "markdown", - "id": "43d1b305", + "id": "326f641d", "metadata": { "editable": true }, @@ -1543,7 +1483,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "595fbc73", + "id": "c8e80cf1", "metadata": { "collapsed": false, "editable": true @@ -1559,7 +1499,7 @@ }, { "cell_type": "markdown", - "id": "85e53450", + "id": "aba7b289", "metadata": { "editable": true }, @@ -1570,7 +1510,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "212cd985", + "id": "7235bf1b", "metadata": { "collapsed": false, "editable": true @@ -1584,7 +1524,7 @@ }, { "cell_type": "markdown", - "id": "74999588", + "id": "3eaf5f8d", "metadata": { "editable": true }, @@ -1605,7 +1545,7 @@ }, { "cell_type": "markdown", - "id": "de135cfe", + "id": "6fc5dc26", "metadata": { "editable": true }, @@ -1616,7 +1556,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "8da1adad", + "id": "98ca5627", "metadata": { "collapsed": false, "editable": true @@ -1669,7 +1609,7 @@ }, { "cell_type": "markdown", - "id": "1b84630e", + "id": "09f0c1c6", "metadata": { "editable": true }, @@ -1680,7 +1620,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "5a629161", + "id": "02220d97", "metadata": { "collapsed": false, "editable": true @@ -1705,7 +1645,7 @@ }, { "cell_type": "markdown", - "id": "2cf10cda", + "id": "5494af4d", "metadata": { "editable": true }, @@ -1717,7 +1657,7 @@ }, { "cell_type": "markdown", - "id": "98555d36", + "id": "048560ee", "metadata": { "editable": true }, @@ -1746,7 +1686,7 @@ }, { "cell_type": "markdown", - "id": "2ce22847", + "id": "85b56c79", "metadata": { "editable": true }, @@ -1771,7 +1711,7 @@ }, { "cell_type": "markdown", - "id": "4f60d380", + "id": "60937483", "metadata": { "editable": true }, @@ -1791,7 +1731,7 @@ }, { "cell_type": "markdown", - "id": "d9467fae", + "id": "5d0ea6a3", "metadata": { "editable": true }, @@ -1818,7 +1758,7 @@ }, { "cell_type": "markdown", - "id": "25ffaddc", + "id": "8f6fc4e6", "metadata": { "editable": true }, @@ -1831,7 +1771,7 @@ }, { "cell_type": "markdown", - "id": "f685ec3d", + "id": "4bd392ed", "metadata": { "editable": true }, @@ -1843,7 +1783,7 @@ }, { "cell_type": "markdown", - "id": "13d97f60", + "id": "4e33d3e3", "metadata": { "editable": true }, @@ -1854,7 +1794,7 @@ }, { "cell_type": "markdown", - "id": "8ae2618e", + "id": "7e1c73ac", "metadata": { "editable": true }, @@ -1870,7 +1810,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "e2fefcfd", + "id": "2c315558", "metadata": { "collapsed": false, "editable": true @@ -1904,7 +1844,7 @@ }, { "cell_type": "markdown", - "id": "dbf80682", + "id": "aaa58775", "metadata": { "editable": true }, @@ -1914,7 +1854,7 @@ }, { "cell_type": "markdown", - "id": "70cad79d", + "id": "02b198ed", "metadata": { "editable": true }, @@ -1929,7 +1869,7 @@ }, { "cell_type": "markdown", - "id": "98479628", + "id": "4cef197d", "metadata": { "editable": true }, @@ -1941,7 +1881,7 @@ }, { "cell_type": "markdown", - "id": "01272daa", + "id": "23b34528", "metadata": { "editable": true }, @@ -1951,7 +1891,7 @@ }, { "cell_type": "markdown", - "id": "c51c9534", + "id": "b2847956", "metadata": { "editable": true }, @@ -1967,7 +1907,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "7d359b4a", + "id": "b8dacc33", "metadata": { "collapsed": false, "editable": true @@ -1984,7 +1924,7 @@ }, { "cell_type": "markdown", - "id": "502ea8a0", + "id": "cd89705f", "metadata": { "editable": true }, @@ -1997,7 +1937,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "532e9ea5", + "id": "d35541fd", "metadata": { "collapsed": false, "editable": true @@ -2044,7 +1984,7 @@ }, { "cell_type": "markdown", - "id": "f9238e17", + "id": "36014ec9", "metadata": { "editable": true }, @@ -2058,7 +1998,7 @@ }, { "cell_type": "markdown", - "id": "922d3ead", + "id": "16fb5f8f", "metadata": { "editable": true }, @@ -2070,7 +2010,7 @@ }, { "cell_type": "markdown", - "id": "09ae2605", + "id": "f1ec698e", "metadata": { "editable": true }, @@ -2082,7 +2022,7 @@ }, { "cell_type": "markdown", - "id": "3b85fa4d", + "id": "787f58f5", "metadata": { "editable": true }, @@ -2094,7 +2034,7 @@ }, { "cell_type": "markdown", - "id": "0a5222ed", + "id": "e23435fd", "metadata": { "editable": true }, @@ -2104,7 +2044,7 @@ }, { "cell_type": "markdown", - "id": "09c8f5af", + "id": "ccaad283", "metadata": { "editable": true }, @@ -2116,7 +2056,7 @@ }, { "cell_type": "markdown", - "id": "eea6cdf3", + "id": "be8092da", "metadata": { "editable": true }, @@ -2126,7 +2066,7 @@ }, { "cell_type": "markdown", - "id": "3f8d62ea", + "id": "6e055e08", "metadata": { "editable": true }, @@ -2138,7 +2078,7 @@ }, { "cell_type": "markdown", - "id": "6f26b43e", + "id": "ff86c9bc", "metadata": { "editable": true }, @@ -2149,7 +2089,7 @@ }, { "cell_type": "markdown", - "id": "c687f732", + "id": "b4f2e747", "metadata": { "editable": true }, @@ -2161,7 +2101,7 @@ }, { "cell_type": "markdown", - "id": "08e588d8", + "id": "5a9a9f87", "metadata": { "editable": true }, @@ -2173,7 +2113,7 @@ }, { "cell_type": "markdown", - "id": "26f0d655", + "id": "1232e11a", "metadata": { "editable": true }, @@ -2183,7 +2123,7 @@ }, { "cell_type": "markdown", - "id": "6d546c67", + "id": "a807825b", "metadata": { "editable": true }, @@ -2195,7 +2135,7 @@ }, { "cell_type": "markdown", - "id": "3245dfb3", + "id": "4fa9855c", "metadata": { "editable": true }, @@ -2207,7 +2147,7 @@ }, { "cell_type": "markdown", - "id": "c1e92387", + "id": "dcffefcf", "metadata": { "editable": true }, @@ -2217,7 +2157,7 @@ }, { "cell_type": "markdown", - "id": "85ce9151", + "id": "3c08ff3a", "metadata": { "editable": true }, @@ -2229,7 +2169,7 @@ }, { "cell_type": "markdown", - "id": "e409c62a", + "id": "c2483a13", "metadata": { "editable": true }, @@ -2239,7 +2179,7 @@ }, { "cell_type": "markdown", - "id": "e2fbb99e", + "id": "9a82a8c5", "metadata": { "editable": true }, @@ -2251,7 +2191,7 @@ }, { "cell_type": "markdown", - "id": "980a4770", + "id": "743f7309", "metadata": { "editable": true }, @@ -2261,7 +2201,7 @@ }, { "cell_type": "markdown", - "id": "d4e69a02", + "id": "e6d7b31a", "metadata": { "editable": true }, @@ -2301,7 +2241,7 @@ }, { "cell_type": "markdown", - "id": "a9d27f27", + "id": "518d6bb4", "metadata": { "editable": true }, @@ -2318,7 +2258,7 @@ }, { "cell_type": "markdown", - "id": "34c1c4c7", + "id": "056673c8", "metadata": { "editable": true }, @@ -2341,7 +2281,7 @@ }, { "cell_type": "markdown", - "id": "4348fb4a", + "id": "63daba59", "metadata": { "editable": true }, @@ -2358,7 +2298,7 @@ }, { "cell_type": "markdown", - "id": "a317d389", + "id": "89b74667", "metadata": { "editable": true }, @@ -2377,7 +2317,7 @@ }, { "cell_type": "markdown", - "id": "46bcba59", + "id": "588dd662", "metadata": { "editable": true }, @@ -2388,7 +2328,7 @@ }, { "cell_type": "markdown", - "id": "9c35f850", + "id": "eb8348c6", "metadata": { "editable": true }, @@ -2400,7 +2340,7 @@ }, { "cell_type": "markdown", - "id": "621042d8", + "id": "62027bc1", "metadata": { "editable": true }, @@ -2418,7 +2358,7 @@ }, { "cell_type": "markdown", - "id": "de7357f3", + "id": "0c73c4b7", "metadata": { "editable": true }, @@ -2434,7 +2374,7 @@ }, { "cell_type": "markdown", - "id": "5f494ff4", + "id": "a3a2d330", "metadata": { "editable": true }, @@ -2446,7 +2386,7 @@ }, { "cell_type": "markdown", - "id": "28bc79e8", + "id": "374b88cc", "metadata": { "editable": true }, @@ -2456,7 +2396,7 @@ }, { "cell_type": "markdown", - "id": "a512fc94", + "id": "d5aa42e6", "metadata": { "editable": true }, @@ -2469,7 +2409,7 @@ }, { "cell_type": "markdown", - "id": "d8ee1379", + "id": "1c01a816", "metadata": { "editable": true }, @@ -2481,7 +2421,7 @@ }, { "cell_type": "markdown", - "id": "f4cd543e", + "id": "f556eddc", "metadata": { "editable": true }, @@ -2491,7 +2431,7 @@ }, { "cell_type": "markdown", - "id": "a795ef02", + "id": "dcf14a16", "metadata": { "editable": true }, @@ -2504,7 +2444,7 @@ }, { "cell_type": "markdown", - "id": "ab55cb45", + "id": "08c37095", "metadata": { "editable": true }, @@ -2514,7 +2454,7 @@ }, { "cell_type": "markdown", - "id": "e0d8f0ac", + "id": "6815fa1b", "metadata": { "editable": true }, @@ -2526,7 +2466,7 @@ }, { "cell_type": "markdown", - "id": "09d5232c", + "id": "daf50946", "metadata": { "editable": true }, @@ -2539,7 +2479,7 @@ }, { "cell_type": "markdown", - "id": "dfe15440", + "id": "a7a60cb3", "metadata": { "editable": true }, @@ -2552,7 +2492,7 @@ }, { "cell_type": "markdown", - "id": "8da79ca2", + "id": "38105bfd", "metadata": { "editable": true }, @@ -2564,7 +2504,7 @@ }, { "cell_type": "markdown", - "id": "52495a50", + "id": "3d697464", "metadata": { "editable": true }, @@ -2576,7 +2516,7 @@ }, { "cell_type": "markdown", - "id": "474f085a", + "id": "c298d7ba", "metadata": { "editable": true }, @@ -2586,7 +2526,7 @@ }, { "cell_type": "markdown", - "id": "ee950778", + "id": "45265b59", "metadata": { "editable": true }, @@ -2599,7 +2539,7 @@ }, { "cell_type": "markdown", - "id": "5ed4b55e", + "id": "ab6ce408", "metadata": { "editable": true }, @@ -2611,7 +2551,7 @@ }, { "cell_type": "markdown", - "id": "49490170", + "id": "ca0350a7", "metadata": { "editable": true }, @@ -2623,7 +2563,7 @@ }, { "cell_type": "markdown", - "id": "31796f9a", + "id": "e8146e6f", "metadata": { "editable": true }, @@ -2635,7 +2575,7 @@ }, { "cell_type": "markdown", - "id": "e125473d", + "id": "05d97a86", "metadata": { "editable": true }, @@ -2647,7 +2587,7 @@ }, { "cell_type": "markdown", - "id": "fceb6842", + "id": "f84e7118", "metadata": { "editable": true }, @@ -2661,7 +2601,7 @@ }, { "cell_type": "markdown", - "id": "c52c50d4", + "id": "28be9ec4", "metadata": { "editable": true }, @@ -2673,7 +2613,7 @@ }, { "cell_type": "markdown", - "id": "0fd07278", + "id": "b9f5a5d8", "metadata": { "editable": true }, @@ -2683,7 +2623,7 @@ }, { "cell_type": "markdown", - "id": "5aa27ad9", + "id": "86b43b21", "metadata": { "editable": true }, @@ -2695,7 +2635,7 @@ }, { "cell_type": "markdown", - "id": "5765d8bb", + "id": "58744172", "metadata": { "editable": true }, @@ -2707,7 +2647,7 @@ }, { "cell_type": "markdown", - "id": "a662eff5", + "id": "dd515e6f", "metadata": { "editable": true }, @@ -2719,7 +2659,7 @@ }, { "cell_type": "markdown", - "id": "fc568ee5", + "id": "e8c98bfe", "metadata": { "editable": true }, @@ -2731,7 +2671,7 @@ }, { "cell_type": "markdown", - "id": "ffaa0b1f", + "id": "08cc9626", "metadata": { "editable": true }, @@ -2743,7 +2683,7 @@ }, { "cell_type": "markdown", - "id": "62b8f7ba", + "id": "725df93e", "metadata": { "editable": true }, @@ -2766,7 +2706,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "b673d4c8", + "id": "8d0397cd", "metadata": { "collapsed": false, "editable": true @@ -2842,7 +2782,7 @@ }, { "cell_type": "markdown", - "id": "0b6d382e", + "id": "dbc56c2b", "metadata": { "editable": true }, @@ -2854,7 +2794,7 @@ }, { "cell_type": "markdown", - "id": "dc27c161", + "id": "cfab477f", "metadata": { "editable": true }, @@ -2869,7 +2809,7 @@ }, { "cell_type": "markdown", - "id": "cd64d24d", + "id": "bc176ed4", "metadata": { "editable": true }, @@ -2881,7 +2821,7 @@ }, { "cell_type": "markdown", - "id": "95a1326b", + "id": "a9eef8e3", "metadata": { "editable": true }, @@ -2891,7 +2831,7 @@ }, { "cell_type": "markdown", - "id": "12abff29", + "id": "c33552ec", "metadata": { "editable": true }, @@ -2903,7 +2843,7 @@ }, { "cell_type": "markdown", - "id": "d76a5478", + "id": "9465d4f6", "metadata": { "editable": true }, @@ -2913,7 +2853,7 @@ }, { "cell_type": "markdown", - "id": "5013c1c5", + "id": "3cd89a35", "metadata": { "editable": true }, @@ -2925,7 +2865,7 @@ }, { "cell_type": "markdown", - "id": "c1c33c2c", + "id": "13a9f453", "metadata": { "editable": true }, @@ -2937,7 +2877,7 @@ }, { "cell_type": "markdown", - "id": "1d6a9248", + "id": "6c909f72", "metadata": { "editable": true }, @@ -2952,7 +2892,7 @@ }, { "cell_type": "markdown", - "id": "50892f07", + "id": "b32ee709", "metadata": { "editable": true }, @@ -2963,7 +2903,7 @@ }, { "cell_type": "markdown", - "id": "eca95ee5", + "id": "e5d3f72c", "metadata": { "editable": true }, @@ -2983,7 +2923,7 @@ }, { "cell_type": "markdown", - "id": "63b6b434", + "id": "18f488f0", "metadata": { "editable": true }, @@ -2995,7 +2935,7 @@ }, { "cell_type": "markdown", - "id": "8fb3c919", + "id": "93618783", "metadata": { "editable": true }, @@ -3005,7 +2945,7 @@ }, { "cell_type": "markdown", - "id": "440f96f8", + "id": "02f57528", "metadata": { "editable": true }, @@ -3017,7 +2957,7 @@ }, { "cell_type": "markdown", - "id": "f762f49e", + "id": "762833f4", "metadata": { "editable": true }, @@ -3046,7 +2986,7 @@ }, { "cell_type": "markdown", - "id": "a2edab48", + "id": "9ab8ec4f", "metadata": { "editable": true }, @@ -3073,7 +3013,7 @@ }, { "cell_type": "markdown", - "id": "2fda8824", + "id": "3e526d1f", "metadata": { "editable": true }, @@ -3084,7 +3024,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "ac2a6237", + "id": "f5d258ce", "metadata": { "collapsed": false, "editable": true @@ -3124,7 +3064,7 @@ }, { "cell_type": "markdown", - "id": "98b3752b", + "id": "4e4bf198", "metadata": { "editable": true }, @@ -3141,7 +3081,7 @@ }, { "cell_type": "markdown", - "id": "b951feca", + "id": "33a42ac4", "metadata": { "editable": true }, @@ -3164,7 +3104,7 @@ }, { "cell_type": "markdown", - "id": "d485a9f4", + "id": "7b5d1bbb", "metadata": { "editable": true }, @@ -3178,7 +3118,7 @@ }, { "cell_type": "markdown", - "id": "c7faaa15", + "id": "1fee5f54", "metadata": { "editable": true }, @@ -3197,7 +3137,7 @@ }, { "cell_type": "markdown", - "id": "037c9894", + "id": "235f2975", "metadata": { "editable": true }, @@ -3207,7 +3147,7 @@ }, { "cell_type": "markdown", - "id": "696b9377", + "id": "fd7415b7", "metadata": { "editable": true }, @@ -3219,7 +3159,7 @@ }, { "cell_type": "markdown", - "id": "50b19ab5", + "id": "7c265b5d", "metadata": { "editable": true }, @@ -3233,7 +3173,7 @@ }, { "cell_type": "markdown", - "id": "391751bc", + "id": "976c31a2", "metadata": { "editable": true }, @@ -3245,7 +3185,7 @@ }, { "cell_type": "markdown", - "id": "704c19fa", + "id": "8dc8acd7", "metadata": { "editable": true }, @@ -3255,7 +3195,7 @@ }, { "cell_type": "markdown", - "id": "24bc8403", + "id": "a1dc8e8e", "metadata": { "editable": true }, @@ -3267,7 +3207,7 @@ }, { "cell_type": "markdown", - "id": "b0a4c80e", + "id": "eb688af0", "metadata": { "editable": true }, @@ -3284,7 +3224,7 @@ }, { "cell_type": "markdown", - "id": "c89a018b", + "id": "eeadd85e", "metadata": { "editable": true }, @@ -3294,7 +3234,7 @@ }, { "cell_type": "markdown", - "id": "b7b1488e", + "id": "e9375ad7", "metadata": { "editable": true }, @@ -3310,7 +3250,7 @@ }, { "cell_type": "markdown", - "id": "1c97d036", + "id": "025f1ca1", "metadata": { "editable": true }, @@ -3320,7 +3260,7 @@ }, { "cell_type": "markdown", - "id": "57b3bb97", + "id": "d44951a1", "metadata": { "editable": true }, @@ -3336,7 +3276,7 @@ }, { "cell_type": "markdown", - "id": "4d9c7d14", + "id": "ecc9216b", "metadata": { "editable": true }, @@ -3346,7 +3286,7 @@ }, { "cell_type": "markdown", - "id": "5f447837", + "id": "28e2ff44", "metadata": { "editable": true }, @@ -3362,7 +3302,7 @@ }, { "cell_type": "markdown", - "id": "1796a94c", + "id": "935324af", "metadata": { "editable": true }, @@ -3372,7 +3312,7 @@ }, { "cell_type": "markdown", - "id": "2f62e2a3", + "id": "a15e7526", "metadata": { "editable": true }, @@ -3389,7 +3329,7 @@ }, { "cell_type": "markdown", - "id": "1268fbe6", + "id": "5d3cef55", "metadata": { "editable": true }, @@ -3401,7 +3341,7 @@ }, { "cell_type": "markdown", - "id": "75a90ae5", + "id": "0fab1783", "metadata": { "editable": true }, @@ -3413,7 +3353,7 @@ }, { "cell_type": "markdown", - "id": "365d5692", + "id": "f9a8450e", "metadata": { "editable": true }, @@ -3425,7 +3365,7 @@ }, { "cell_type": "markdown", - "id": "6a44126b", + "id": "485d1023", "metadata": { "editable": true }, @@ -3435,7 +3375,7 @@ }, { "cell_type": "markdown", - "id": "62236a82", + "id": "a2da5dbe", "metadata": { "editable": true }, @@ -3447,7 +3387,7 @@ }, { "cell_type": "markdown", - "id": "6f9af7b1", + "id": "13959099", "metadata": { "editable": true }, @@ -3459,7 +3399,7 @@ }, { "cell_type": "markdown", - "id": "bfaf73c2", + "id": "23f0b903", "metadata": { "editable": true }, @@ -3471,7 +3411,7 @@ }, { "cell_type": "markdown", - "id": "2dfeada7", + "id": "1c344e77", "metadata": { "editable": true }, @@ -3481,7 +3421,7 @@ }, { "cell_type": "markdown", - "id": "c858189d", + "id": "d8064053", "metadata": { "editable": true }, @@ -3493,7 +3433,7 @@ }, { "cell_type": "markdown", - "id": "bc2dcc08", + "id": "714ab01f", "metadata": { "editable": true }, @@ -3503,7 +3443,7 @@ }, { "cell_type": "markdown", - "id": "72f6cfbe", + "id": "a3ff6988", "metadata": { "editable": true }, @@ -3515,7 +3455,7 @@ }, { "cell_type": "markdown", - "id": "cfcdd05d", + "id": "5c204f79", "metadata": { "editable": true }, @@ -3531,7 +3471,7 @@ }, { "cell_type": "markdown", - "id": "0733a9b6", + "id": "78c51f10", "metadata": { "editable": true }, @@ -3543,7 +3483,7 @@ }, { "cell_type": "markdown", - "id": "451805d9", + "id": "2c432ed4", "metadata": { "editable": true }, @@ -3555,7 +3495,7 @@ }, { "cell_type": "markdown", - "id": "1f256ec7", + "id": "68a7b505", "metadata": { "editable": true }, @@ -3565,7 +3505,7 @@ }, { "cell_type": "markdown", - "id": "5508ea91", + "id": "14268cd5", "metadata": { "editable": true }, @@ -3577,7 +3517,7 @@ }, { "cell_type": "markdown", - "id": "8d248db6", + "id": "f3207844", "metadata": { "editable": true }, @@ -3588,7 +3528,7 @@ }, { "cell_type": "markdown", - "id": "e85386b6", + "id": "4c7f5556", "metadata": { "editable": true }, @@ -3600,7 +3540,7 @@ }, { "cell_type": "markdown", - "id": "256fd27b", + "id": "01bd8826", "metadata": { "editable": true }, @@ -3610,7 +3550,7 @@ }, { "cell_type": "markdown", - "id": "bac1ca17", + "id": "cb083248", "metadata": { "editable": true }, @@ -3622,7 +3562,7 @@ }, { "cell_type": "markdown", - "id": "ee770bab", + "id": "66bd1ec9", "metadata": { "editable": true }, @@ -3632,7 +3572,7 @@ }, { "cell_type": "markdown", - "id": "861507ad", + "id": "b92a06bb", "metadata": { "editable": true }, @@ -3644,7 +3584,7 @@ }, { "cell_type": "markdown", - "id": "892dfd49", + "id": "dad0b409", "metadata": { "editable": true }, @@ -3655,7 +3595,7 @@ }, { "cell_type": "markdown", - "id": "22f9c10a", + "id": "75d85fa8", "metadata": { "editable": true }, @@ -3667,7 +3607,7 @@ }, { "cell_type": "markdown", - "id": "bdac90fb", + "id": "d0918773", "metadata": { "editable": true }, @@ -3685,7 +3625,7 @@ }, { "cell_type": "markdown", - "id": "ca5b3148", + "id": "65592b3b", "metadata": { "editable": true }, @@ -3701,7 +3641,7 @@ }, { "cell_type": "markdown", - "id": "3ae061ab", + "id": "442404b8", "metadata": { "editable": true }, @@ -3713,7 +3653,7 @@ }, { "cell_type": "markdown", - "id": "a3ecde55", + "id": "50eca816", "metadata": { "editable": true }, @@ -3725,7 +3665,7 @@ }, { "cell_type": "markdown", - "id": "b9ca21b6", + "id": "a27e487e", "metadata": { "editable": true }, @@ -3737,7 +3677,7 @@ }, { "cell_type": "markdown", - "id": "d0b95a34", + "id": "49c74d48", "metadata": { "editable": true }, @@ -3750,7 +3690,7 @@ }, { "cell_type": "markdown", - "id": "3af0b126", + "id": "214feab7", "metadata": { "editable": true }, @@ -3766,7 +3706,7 @@ }, { "cell_type": "markdown", - "id": "2a2ab94a", + "id": "e61c0669", "metadata": { "editable": true }, @@ -3780,7 +3720,7 @@ }, { "cell_type": "markdown", - "id": "702a8a7c", + "id": "9f3db006", "metadata": { "editable": true }, @@ -3790,7 +3730,7 @@ }, { "cell_type": "markdown", - "id": "a32f687d", + "id": "6dfeb8ca", "metadata": { "editable": true }, @@ -3802,7 +3742,7 @@ }, { "cell_type": "markdown", - "id": "e46d532c", + "id": "da47505d", "metadata": { "editable": true }, @@ -3812,7 +3752,7 @@ }, { "cell_type": "markdown", - "id": "2c236619", + "id": "87c1a756", "metadata": { "editable": true }, @@ -3824,7 +3764,7 @@ }, { "cell_type": "markdown", - "id": "a7cc52c9", + "id": "5028dae1", "metadata": { "editable": true }, @@ -3834,7 +3774,7 @@ }, { "cell_type": "markdown", - "id": "ec8fb144", + "id": "98da161b", "metadata": { "editable": true }, @@ -3848,7 +3788,7 @@ }, { "cell_type": "markdown", - "id": "d70ec924", + "id": "69065ef4", "metadata": { "editable": true }, @@ -3865,7 +3805,7 @@ }, { "cell_type": "markdown", - "id": "36373c95", + "id": "3455143e", "metadata": { "editable": true }, @@ -3881,7 +3821,7 @@ }, { "cell_type": "markdown", - "id": "e9e1a2cf", + "id": "e322fdc8", "metadata": { "editable": true }, @@ -3893,7 +3833,7 @@ }, { "cell_type": "markdown", - "id": "dbdf343c", + "id": "f50b583d", "metadata": { "editable": true }, @@ -3906,7 +3846,7 @@ }, { "cell_type": "markdown", - "id": "00fca060", + "id": "b12b62dc", "metadata": { "editable": true }, @@ -3920,7 +3860,7 @@ }, { "cell_type": "markdown", - "id": "089fbc50", + "id": "40355c87", "metadata": { "editable": true }, @@ -3930,7 +3870,7 @@ }, { "cell_type": "markdown", - "id": "aa7d56de", + "id": "ee70666b", "metadata": { "editable": true }, @@ -3943,7 +3883,7 @@ }, { "cell_type": "markdown", - "id": "107e7e56", + "id": "dc6d0cc7", "metadata": { "editable": true }, @@ -3962,7 +3902,7 @@ }, { "cell_type": "markdown", - "id": "d03f9df3", + "id": "d6b6f792", "metadata": { "editable": true }, @@ -3974,7 +3914,7 @@ }, { "cell_type": "markdown", - "id": "83cdef65", + "id": "39c76bf5", "metadata": { "editable": true }, @@ -3986,7 +3926,7 @@ }, { "cell_type": "markdown", - "id": "184bc23e", + "id": "f2d754e5", "metadata": { "editable": true }, @@ -3996,7 +3936,7 @@ }, { "cell_type": "markdown", - "id": "d7a360b1", + "id": "77a984ab", "metadata": { "editable": true }, @@ -4008,7 +3948,7 @@ }, { "cell_type": "markdown", - "id": "a8d9eab3", + "id": "33060c1a", "metadata": { "editable": true }, @@ -4021,7 +3961,7 @@ }, { "cell_type": "markdown", - "id": "0d96192e", + "id": "ed1e8279", "metadata": { "editable": true }, @@ -4040,7 +3980,7 @@ }, { "cell_type": "markdown", - "id": "e3a740c0", + "id": "22b40263", "metadata": { "editable": true }, @@ -4050,7 +3990,7 @@ }, { "cell_type": "markdown", - "id": "cfecb052", + "id": "1b02469c", "metadata": { "editable": true }, @@ -4069,7 +4009,7 @@ }, { "cell_type": "markdown", - "id": "ab630965", + "id": "0660e456", "metadata": { "editable": true }, @@ -4087,7 +4027,7 @@ }, { "cell_type": "markdown", - "id": "65b5bc6d", + "id": "0a40e5c0", "metadata": { "editable": true }, @@ -4101,7 +4041,7 @@ }, { "cell_type": "markdown", - "id": "2975ddee", + "id": "82d7e99d", "metadata": { "editable": true }, @@ -4116,7 +4056,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "42516f04", + "id": "6f4b429b", "metadata": { "collapsed": false, "editable": true @@ -4137,7 +4077,7 @@ }, { "cell_type": "markdown", - "id": "7a8ba0a5", + "id": "a38f8430", "metadata": { "editable": true }, @@ -4154,7 +4094,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "f4d191d3", + "id": "87d44fdf", "metadata": { "collapsed": false, "editable": true @@ -4186,7 +4126,7 @@ }, { "cell_type": "markdown", - "id": "6667b538", + "id": "5f08f4dc", "metadata": { "editable": true }, @@ -4200,7 +4140,7 @@ }, { "cell_type": "markdown", - "id": "da9e063a", + "id": "a25b356f", "metadata": { "editable": true }, @@ -4213,7 +4153,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "7f9b97fd", + "id": "928ae649", "metadata": { "collapsed": false, "editable": true @@ -4238,7 +4178,7 @@ }, { "cell_type": "markdown", - "id": "9ac5ff2a", + "id": "cab70377", "metadata": { "editable": true }, @@ -4250,7 +4190,7 @@ }, { "cell_type": "markdown", - "id": "76c777e2", + "id": "22ac4a6d", "metadata": { "editable": true }, @@ -4262,7 +4202,7 @@ }, { "cell_type": "markdown", - "id": "3ec85318", + "id": "cd0697a9", "metadata": { "editable": true }, @@ -4272,7 +4212,7 @@ }, { "cell_type": "markdown", - "id": "1181ecdf", + "id": "b5043405", "metadata": { "editable": true }, @@ -4289,7 +4229,7 @@ }, { "cell_type": "markdown", - "id": "a5af19b2", + "id": "6a4edab6", "metadata": { "editable": true }, @@ -4299,7 +4239,7 @@ }, { "cell_type": "markdown", - "id": "93617c8e", + "id": "e1b67496", "metadata": { "editable": true }, @@ -4314,7 +4254,7 @@ }, { "cell_type": "markdown", - "id": "7362ac99", + "id": "47a041cb", "metadata": { "editable": true }, @@ -4324,7 +4264,7 @@ }, { "cell_type": "markdown", - "id": "6b6f4204", + "id": "575264b7", "metadata": { "editable": true }, @@ -4338,7 +4278,7 @@ }, { "cell_type": "markdown", - "id": "e8509c17", + "id": "7b049c58", "metadata": { "editable": true }, @@ -4350,7 +4290,7 @@ }, { "cell_type": "markdown", - "id": "31eaa9da", + "id": "9780789f", "metadata": { "editable": true }, @@ -4362,7 +4302,7 @@ }, { "cell_type": "markdown", - "id": "91e1e4f3", + "id": "da396c4a", "metadata": { "editable": true }, @@ -4374,7 +4314,7 @@ }, { "cell_type": "markdown", - "id": "3f120534", + "id": "87a74417", "metadata": { "editable": true }, @@ -4384,7 +4324,7 @@ }, { "cell_type": "markdown", - "id": "d295c48a", + "id": "c5ca565a", "metadata": { "editable": true }, @@ -4396,7 +4336,7 @@ }, { "cell_type": "markdown", - "id": "48764fe6", + "id": "10944fc5", "metadata": { "editable": true }, @@ -4406,7 +4346,7 @@ }, { "cell_type": "markdown", - "id": "f18b11a7", + "id": "7b985955", "metadata": { "editable": true }, @@ -4423,7 +4363,7 @@ }, { "cell_type": "markdown", - "id": "3d45ace3", + "id": "1b748051", "metadata": { "editable": true }, @@ -4433,7 +4373,7 @@ }, { "cell_type": "markdown", - "id": "6ed92786", + "id": "40c1c1eb", "metadata": { "editable": true }, @@ -4445,7 +4385,7 @@ }, { "cell_type": "markdown", - "id": "699bc17b", + "id": "e44c9e87", "metadata": { "editable": true }, @@ -4455,7 +4395,7 @@ }, { "cell_type": "markdown", - "id": "be0daf6e", + "id": "28abe46c", "metadata": { "editable": true }, @@ -4467,7 +4407,7 @@ }, { "cell_type": "markdown", - "id": "7ab036f2", + "id": "178bc776", "metadata": { "editable": true }, @@ -4481,7 +4421,7 @@ }, { "cell_type": "markdown", - "id": "e64350c4", + "id": "1f0ead95", "metadata": { "editable": true }, @@ -4493,7 +4433,7 @@ }, { "cell_type": "markdown", - "id": "18877c04", + "id": "fcce3bb5", "metadata": { "editable": true }, @@ -4515,7 +4455,7 @@ }, { "cell_type": "markdown", - "id": "d6d7ec53", + "id": "5f9a7281", "metadata": { "editable": true }, @@ -4527,7 +4467,7 @@ }, { "cell_type": "markdown", - "id": "8c7cd5a1", + "id": "d3ea695c", "metadata": { "editable": true }, @@ -4542,7 +4482,7 @@ }, { "cell_type": "markdown", - "id": "50a53777", + "id": "edfff9e0", "metadata": { "editable": true }, @@ -4554,7 +4494,7 @@ }, { "cell_type": "markdown", - "id": "9b8537df", + "id": "c3c83244", "metadata": { "editable": true }, @@ -4566,7 +4506,7 @@ }, { "cell_type": "markdown", - "id": "c2b2b605", + "id": "00df5ee5", "metadata": { "editable": true }, @@ -4576,7 +4516,7 @@ }, { "cell_type": "markdown", - "id": "7f59c734", + "id": "4661cbd7", "metadata": { "editable": true }, @@ -4588,7 +4528,7 @@ }, { "cell_type": "markdown", - "id": "bf68545f", + "id": "07b95265", "metadata": { "editable": true }, @@ -4598,7 +4538,7 @@ }, { "cell_type": "markdown", - "id": "5680d812", + "id": "8c9aeba4", "metadata": { "editable": true }, @@ -4610,7 +4550,7 @@ }, { "cell_type": "markdown", - "id": "4f51737b", + "id": "03690a72", "metadata": { "editable": true }, @@ -4620,7 +4560,7 @@ }, { "cell_type": "markdown", - "id": "53dc7de3", + "id": "478e2a9d", "metadata": { "editable": true }, @@ -4632,7 +4572,7 @@ }, { "cell_type": "markdown", - "id": "8360ef9d", + "id": "e997196a", "metadata": { "editable": true }, @@ -4649,7 +4589,7 @@ }, { "cell_type": "markdown", - "id": "ec0dfe91", + "id": "770e587e", "metadata": { "editable": true }, @@ -4662,7 +4602,7 @@ }, { "cell_type": "markdown", - "id": "34152030", + "id": "5cb701c2", "metadata": { "editable": true }, @@ -4674,7 +4614,7 @@ }, { "cell_type": "markdown", - "id": "b3fc72ca", + "id": "dee9d948", "metadata": { "editable": true }, @@ -4684,7 +4624,7 @@ }, { "cell_type": "markdown", - "id": "36274568", + "id": "121cd014", "metadata": { "editable": true }, @@ -4697,7 +4637,7 @@ }, { "cell_type": "markdown", - "id": "5b3ef5a2", + "id": "2ee745b4", "metadata": { "editable": true }, @@ -4707,7 +4647,7 @@ }, { "cell_type": "markdown", - "id": "204fb658", + "id": "94a15fb9", "metadata": { "editable": true }, @@ -4719,7 +4659,7 @@ }, { "cell_type": "markdown", - "id": "f4f187e8", + "id": "6341fe06", "metadata": { "editable": true }, @@ -4732,7 +4672,7 @@ }, { "cell_type": "markdown", - "id": "b339f5f8", + "id": "5bef6925", "metadata": { "editable": true }, @@ -4745,7 +4685,7 @@ }, { "cell_type": "markdown", - "id": "8e55f463", + "id": "4539e82b", "metadata": { "editable": true }, @@ -4757,7 +4697,7 @@ }, { "cell_type": "markdown", - "id": "f60475c2", + "id": "1f496d16", "metadata": { "editable": true }, @@ -4769,7 +4709,7 @@ }, { "cell_type": "markdown", - "id": "f8d60ad3", + "id": "ee78adfa", "metadata": { "editable": true }, @@ -4779,7 +4719,7 @@ }, { "cell_type": "markdown", - "id": "a8d82e40", + "id": "47a0c860", "metadata": { "editable": true }, @@ -4792,7 +4732,7 @@ }, { "cell_type": "markdown", - "id": "0717bbf7", + "id": "6b452b5d", "metadata": { "editable": true }, @@ -4804,7 +4744,7 @@ }, { "cell_type": "markdown", - "id": "8624e757", + "id": "a3331a79", "metadata": { "editable": true }, @@ -4816,7 +4756,7 @@ }, { "cell_type": "markdown", - "id": "a71d8b33", + "id": "9befd0e3", "metadata": { "editable": true }, @@ -4833,7 +4773,7 @@ }, { "cell_type": "markdown", - "id": "234fe794", + "id": "9d8f2ba3", "metadata": { "editable": true }, @@ -4845,7 +4785,7 @@ }, { "cell_type": "markdown", - "id": "994af919", + "id": "da712e9d", "metadata": { "editable": true }, @@ -4855,7 +4795,7 @@ }, { "cell_type": "markdown", - "id": "1292a010", + "id": "d91cd5f7", "metadata": { "editable": true }, @@ -4867,7 +4807,7 @@ }, { "cell_type": "markdown", - "id": "75dbb009", + "id": "18940f72", "metadata": { "editable": true }, @@ -4877,7 +4817,7 @@ }, { "cell_type": "markdown", - "id": "ba4b130b", + "id": "51fe3527", "metadata": { "editable": true }, @@ -4889,7 +4829,7 @@ }, { "cell_type": "markdown", - "id": "31f13272", + "id": "2e85d1eb", "metadata": { "editable": true }, @@ -4901,7 +4841,7 @@ }, { "cell_type": "markdown", - "id": "0e0cf0c5", + "id": "96c47485", "metadata": { "editable": true }, @@ -4917,7 +4857,7 @@ }, { "cell_type": "markdown", - "id": "c32074fc", + "id": "c1adcbbc", "metadata": { "editable": true }, @@ -4929,7 +4869,7 @@ }, { "cell_type": "markdown", - "id": "816b4de6", + "id": "9693074c", "metadata": { "editable": true }, @@ -4941,7 +4881,7 @@ }, { "cell_type": "markdown", - "id": "f6bff531", + "id": "46b05531", "metadata": { "editable": true }, @@ -4951,7 +4891,7 @@ }, { "cell_type": "markdown", - "id": "94321e3c", + "id": "2e4ce02b", "metadata": { "editable": true }, @@ -4963,7 +4903,7 @@ }, { "cell_type": "markdown", - "id": "bd032cec", + "id": "dbd3f781", "metadata": { "editable": true }, @@ -4973,7 +4913,7 @@ }, { "cell_type": "markdown", - "id": "6f42aa5f", + "id": "779e1ac5", "metadata": { "editable": true }, @@ -4985,7 +4925,7 @@ }, { "cell_type": "markdown", - "id": "42995fa9", + "id": "ef53f2a5", "metadata": { "editable": true }, @@ -5002,7 +4942,7 @@ }, { "cell_type": "markdown", - "id": "6842e635", + "id": "57adfaff", "metadata": { "editable": true }, @@ -5014,7 +4954,7 @@ }, { "cell_type": "markdown", - "id": "0dae9d38", + "id": "a8f94cba", "metadata": { "editable": true }, @@ -5026,7 +4966,7 @@ }, { "cell_type": "markdown", - "id": "a1ab7f55", + "id": "d60431ff", "metadata": { "editable": true }, @@ -5036,7 +4976,7 @@ }, { "cell_type": "markdown", - "id": "b27417e4", + "id": "f78d1dfd", "metadata": { "editable": true }, @@ -5048,7 +4988,7 @@ }, { "cell_type": "markdown", - "id": "d1657677", + "id": "445800de", "metadata": { "editable": true }, @@ -5058,7 +4998,7 @@ }, { "cell_type": "markdown", - "id": "f025da00", + "id": "3c54c49c", "metadata": { "editable": true }, @@ -5070,7 +5010,7 @@ }, { "cell_type": "markdown", - "id": "644d8ae3", + "id": "11366dc1", "metadata": { "editable": true }, @@ -5080,7 +5020,7 @@ }, { "cell_type": "markdown", - "id": "5096b46d", + "id": "d68d3ac1", "metadata": { "editable": true }, @@ -5092,7 +5032,7 @@ }, { "cell_type": "markdown", - "id": "0b2c777f", + "id": "63fedbd6", "metadata": { "editable": true }, @@ -5102,7 +5042,7 @@ }, { "cell_type": "markdown", - "id": "67b3c2d0", + "id": "470b20a8", "metadata": { "editable": true }, @@ -5114,7 +5054,7 @@ }, { "cell_type": "markdown", - "id": "b3a8787b", + "id": "f3277c65", "metadata": { "editable": true }, diff --git a/doc/src/week35/week35.do.txt b/doc/src/week35/week35.do.txt index c092bbcc2..4661992f2 100644 --- a/doc/src/week35/week35.do.txt +++ b/doc/src/week35/week35.do.txt @@ -155,7 +155,7 @@ will treat $y_i$ as our exact value for the output variable. In order to find the parameters $\theta_i$ we will then minimize the spread of $C(\bm{\theta})$, that is we are going to solve the problem !bt \[ -{\displaystyle \min_{\bm{\theta}\in +\hat{\bm{\theta}}={\displaystyle \min_{\bm{\theta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\theta}\right)^T\left(\bm{y}-\bm{X}\bm{\theta}\right)\right\}. \] !et @@ -197,7 +197,7 @@ as and if the matrix $\bm{X}^T\bm{X}$ is invertible we have the solution !bt \[ -\bm{\theta} =\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}. +\hat{\bm{\theta}} =\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}. \] !et @@ -209,11 +209,11 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as _LU_ decomposition or _Singular Value Decomposition_ (SVD) for finding the inverse of the matrix -$\bm{X}^T\bm{X}$. This is discussed on Thursday this week. +$\bm{X}^T\bm{X}$. !eblock !bblock -_Small question_: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix $\bm{X}^T\bm{X}$? What kind of problems can we expect? +_Small question_: When inverting the matrix $\bm{X}^T\bm{X}, what kind of problems can we expect? !eblock !split @@ -471,34 +471,6 @@ or as -!split -===== Other useful relations ===== - -We list here some other useful relations we may encounter (recall that vectors are defined by boldfaced low-key letters) -!bt -\[ -\frac{\partial (\bm{x}^T\bm{a})}{\partial \bm{x}} = \bm{a}^T, -\] -!et -!bt -\[ -\frac{\partial (\bm{a}^T\bm{x})}{\partial \bm{x}} = \bm{a}^T, -\] -!et - -!bt -\[ -\frac{\partial tr(\bm{B}\bm{A})}{\partial \bm{A}} = \bm{B}^T, -\] -!et -!bt -\[ -\frac{\partial \log{\vert\bm{A}\vert}}{\partial \bm{A}} = (\bm{A}^{-1})^T. -\] -!et - - - !split ===== Meet the Hessian Matrix ===== @@ -526,11 +498,11 @@ The Hessian matrix plays an important role and is defined here as For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters -$\hat{\bm{\theta}}$. Furthermore, we will see later this week that it is +$\hat{\bm{\theta}}$. Furthermore, we will see next week that it is (aside the factor $1/n$) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning/data analysis -problem. +problem. We will discuss this in greater detail next week when we introduce gradient methods. _Linear algebra question:_ Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!).