diff --git a/doc/pub/week35/html/._week35-bs000.html b/doc/pub/week35/html/._week35-bs000.html index 3a6fa9a41..103514007 100644 --- a/doc/pub/week35/html/._week35-bs000.html +++ b/doc/pub/week35/html/._week35-bs000.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -434,7 +436,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs001.html b/doc/pub/week35/html/._week35-bs001.html index 3b93c9c52..24bdc150f 100644 --- a/doc/pub/week35/html/._week35-bs001.html +++ b/doc/pub/week35/html/._week35-bs001.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -427,7 +429,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs002.html b/doc/pub/week35/html/._week35-bs002.html index 82afcddfc..8dd460bd4 100644 --- a/doc/pub/week35/html/._week35-bs002.html +++ b/doc/pub/week35/html/._week35-bs002.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -428,7 +430,7 @@ Similarly, Mehta et al
  • 11
  • 12
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs003.html b/doc/pub/week35/html/._week35-bs003.html index a3af94f99..693c68d8e 100644 --- a/doc/pub/week35/html/._week35-bs003.html +++ b/doc/pub/week35/html/._week35-bs003.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -429,7 +431,7 @@ The first variable is called the dependent, the outcome or the
  • 12
  • 13
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs004.html b/doc/pub/week35/html/._week35-bs004.html index 3dbaf6de2..2f2cbf93d 100644 --- a/doc/pub/week35/html/._week35-bs004.html +++ b/doc/pub/week35/html/._week35-bs004.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -438,7 +440,7 @@ the linear regression model where \( \boldsymbol{\beta} = [\beta_0, \ld
  • 13
  • 14
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs005.html b/doc/pub/week35/html/._week35-bs005.html index b08690218..30a70a167 100644 --- a/doc/pub/week35/html/._week35-bs005.html +++ b/doc/pub/week35/html/._week35-bs005.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -438,7 +440,7 @@ so-called 14
  • 15
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs006.html b/doc/pub/week35/html/._week35-bs006.html index 25f1dbadb..36e3797bd 100644 --- a/doc/pub/week35/html/._week35-bs006.html +++ b/doc/pub/week35/html/._week35-bs006.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -428,7 +430,7 @@ $$
  • 15
  • 16
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs007.html b/doc/pub/week35/html/._week35-bs007.html index 921b69887..3c140236e 100644 --- a/doc/pub/week35/html/._week35-bs007.html +++ b/doc/pub/week35/html/._week35-bs007.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -431,7 +433,7 @@ $$
  • 16
  • 17
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs008.html b/doc/pub/week35/html/._week35-bs008.html index 5e2912090..db5dde80f 100644 --- a/doc/pub/week35/html/._week35-bs008.html +++ b/doc/pub/week35/html/._week35-bs008.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -455,7 +457,7 @@ $$
  • 17
  • 18
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs009.html b/doc/pub/week35/html/._week35-bs009.html index 4b5791b80..37fc6b20e 100644 --- a/doc/pub/week35/html/._week35-bs009.html +++ b/doc/pub/week35/html/._week35-bs009.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -445,7 +447,7 @@ $$
  • 18
  • 19
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs010.html b/doc/pub/week35/html/._week35-bs010.html index c788516b0..a46289bf8 100644 --- a/doc/pub/week35/html/._week35-bs010.html +++ b/doc/pub/week35/html/._week35-bs010.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -442,7 +444,7 @@ $$
  • 19
  • 20
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs011.html b/doc/pub/week35/html/._week35-bs011.html index 61e67ef08..a63feaa60 100644 --- a/doc/pub/week35/html/._week35-bs011.html +++ b/doc/pub/week35/html/._week35-bs011.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -441,7 +443,7 @@ our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predict
  • 20
  • 21
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs012.html b/doc/pub/week35/html/._week35-bs012.html index 7c3c4aa85..a87bdace4 100644 --- a/doc/pub/week35/html/._week35-bs012.html +++ b/doc/pub/week35/html/._week35-bs012.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -519,7 +521,7 @@ $$
  • 21
  • 22
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs013.html b/doc/pub/week35/html/._week35-bs013.html index b77253763..3bb62728f 100644 --- a/doc/pub/week35/html/._week35-bs013.html +++ b/doc/pub/week35/html/._week35-bs013.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -450,7 +452,7 @@ $$
  • 22
  • 23
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs014.html b/doc/pub/week35/html/._week35-bs014.html index 19a78961e..fd03a2cf0 100644 --- a/doc/pub/week35/html/._week35-bs014.html +++ b/doc/pub/week35/html/._week35-bs014.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -467,7 +469,7 @@ $$
  • 23
  • 24
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs015.html b/doc/pub/week35/html/._week35-bs015.html index e35dd9372..3c1e372a3 100644 --- a/doc/pub/week35/html/._week35-bs015.html +++ b/doc/pub/week35/html/._week35-bs015.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -458,7 +460,7 @@ allow for the usage of direct linear algebra methods such as LU decomposi
  • 24
  • 25
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs016.html b/doc/pub/week35/html/._week35-bs016.html index eb56f6e90..ba889e232 100644 --- a/doc/pub/week35/html/._week35-bs016.html +++ b/doc/pub/week35/html/._week35-bs016.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -443,7 +445,7 @@ $$
  • 25
  • 26
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs017.html b/doc/pub/week35/html/._week35-bs017.html index 10a327678..34a4d027d 100644 --- a/doc/pub/week35/html/._week35-bs017.html +++ b/doc/pub/week35/html/._week35-bs017.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -409,6 +411,12 @@ on the other hand \( \boldsymbol{y} \) is a scalar, the Jacobian becomes a \( 1\times n \) matrix.

    +

    When this matrix is a square matrix \( m=n \), its determinant is often referred to as the Jacobian +determinant. Both the matrix and (if \( m=n \)) the determinant are +often referred to simply as the Jacobian. The Jacobian matrix represents the differential of \( \boldsymbol{y} \) at every point where the +vector is differentiable. +

    +

    diff --git a/doc/pub/week35/html/._week35-bs018.html b/doc/pub/week35/html/._week35-bs018.html index 79064a873..23153231d 100644 --- a/doc/pub/week35/html/._week35-bs018.html +++ b/doc/pub/week35/html/._week35-bs018.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -413,24 +415,6 @@ $$ $$ -$$ -\frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, -$$ - -$$ -\frac{\partial (\boldsymbol{a}^T\boldsymbol{A}\boldsymbol{a})}{\partial \boldsymbol{a}} = (\boldsymbol{A}+\boldsymbol{A}^T)\boldsymbol{a}, -$$ - -$$ -\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. -$$ - -

    See the jupyter-book (complete lecture notes) for the derivations of these relations.

    -

    diff --git a/doc/pub/week35/html/._week35-bs019.html b/doc/pub/week35/html/._week35-bs019.html index 258b9aa69..475156e70 100644 --- a/doc/pub/week35/html/._week35-bs019.html +++ b/doc/pub/week35/html/._week35-bs019.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,35 +393,50 @@ MathJax.Hub.Config({

     

     

     

    -

    Meet the Hessian Matrix

    +

    Example 2

    -

    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 parameter \( \beta \). Using the above -expression for derivatives of vectors and matrices, we find that the -second derivative of the cost function is, +

    We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications

    + +$$ +\alpha = \boldsymbol{y}^T\boldsymbol{A}\boldsymbol{x}$, +$$ + +

    with \( \boldsymbol{y} \) a vector of length \( m \), \( \boldsymbol{A} \) an \( m\times n \) matrix and \( \boldsymbol{x} \) a vector of length \( n \). We assume also that \( \boldsymbol{A} \) does not depend on any of the two vectors. +In order to find the derivative of \( \alpha \) with respect to the two vectors, we define an intermediate vector \( \boldsymbol{z} \). We define first +\( \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A} \), a vector of length \( n \). We have then

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

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

    - +

    which means that (using our previous example) we have

    $$ -\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +\frac{\partial \alpha}{\partial \boldsymbol{x}} = \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A}. $$ -

    For ordinary least squares, it is inversely proportional (derivation -next week) with the variance of the optimal parameters -\( \hat{\boldsymbol{\beta}} \). Furthermore, we will see later this week that is -(beside \( 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 -problem. -

    +

    Since \( \alpha \) is a scalar we have \( \alpha =\alpha^T=\boldsymbol{x}^T\boldsymbol{A}^T\boldsymbol{y} \). Defining now \( \boldsymbol{z}=\boldsymbol{x}^T\boldsymbol{A}^T \) we find that

    +$$ +\frac{\partial \alpha}{\partial \boldsymbol{y}} = \boldsymbol{z}^T=\boldsymbol{x}^T\boldsymbol{A}^T.. +$$ -

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

    + +$$ +\frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, +$$ + +$$ +\frac{\partial (\boldsymbol{a}^T\boldsymbol{A}\boldsymbol{a})}{\partial \boldsymbol{a}} = (\boldsymbol{A}+\boldsymbol{A}^T)\boldsymbol{a}, +$$ + +$$ +\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. +$$ + +

    See the jupyter-book (complete lecture notes) for the derivations of these relations.

    @@ -446,7 +463,7 @@ problem.

  • 28
  • 29
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs020.html b/doc/pub/week35/html/._week35-bs020.html index 7acea4ed4..66bd27cac 100644 --- a/doc/pub/week35/html/._week35-bs020.html +++ b/doc/pub/week35/html/._week35-bs020.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,29 +393,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Interpretations and optimizing our parameters

    -
    -
    - -

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

    +

    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 parameter \( \beta \). Using the above +expression for derivatives of vectors and matrices, we find that the +second derivative of the cost function is, +

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

    and with

    +

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

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

    we have

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

    meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.

    -
    -
    +

    For ordinary least squares, it is inversely proportional (derivation +next week) with the variance of the optimal parameters +\( \hat{\boldsymbol{\beta}} \). Furthermore, we will see later this week that is +(beside \( 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 +problem. +

    +

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

    @@ -440,7 +448,7 @@ $$

  • 29
  • 30
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs021.html b/doc/pub/week35/html/._week35-bs021.html index 94dfaf52d..415bc5984 100644 --- a/doc/pub/week35/html/._week35-bs021.html +++ b/doc/pub/week35/html/._week35-bs021.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,95 +393,27 @@ MathJax.Hub.Config({

     

     

     

    -

    Own code for Ordinary Least Squares

    +

    Interpretations and optimizing our parameters

    +
    +
    + +

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

    +$$ +\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}, +$$ -

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to -write -

    +

    and with

    +$$ +\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, +$$ - -
    -
    -
    -
    -
    -
    # matrix inversion to find beta
    -beta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Energies)
    -# and then make the prediction
    -ytilde = X @ beta
    -
    +

    we have

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

    meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.

    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

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

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

    And finally we plot our fit with and compare with data

    - - -
    -
    -
    -
    -
    -
    Masses['Eapprox']  = ytilde
    -# Generate a plot comparing the experimental with the fitted values values.
    -fig, ax = plt.subplots()
    -ax.set_xlabel(r'$A = N + Z$')
    -ax.set_ylabel(r'$E_\mathrm{bind}\,/\mathrm{MeV}$')
    -ax.plot(Masses['A'], Masses['Ebinding'], alpha=0.7, lw=2,
    -            label='Ame2016')
    -ax.plot(Masses['A'], Masses['Eapprox'], alpha=0.7, lw=2, c='m',
    -            label='Fit')
    -ax.legend()
    -save_fig("Masses2016OLS")
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    @@ -508,7 +442,7 @@ plt.show()
  • 30
  • 31
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs022.html b/doc/pub/week35/html/._week35-bs022.html index ee5afaaa9..378ee1e23 100644 --- a/doc/pub/week35/html/._week35-bs022.html +++ b/doc/pub/week35/html/._week35-bs022.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,10 +393,10 @@ MathJax.Hub.Config({

     

     

     

    -

    Adding error analysis and training set up

    +

    Own code for Ordinary Least Squares

    -

    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 rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to +write

    @@ -403,8 +405,10 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
    -
    def R2(y_data, y_model):
    -    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    +  
    # matrix inversion to find beta
    +beta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Energies)
    +# and then make the prediction
    +ytilde = X @ beta
     
    @@ -420,7 +424,7 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
    -

    and we would be using it as

    +

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

    @@ -428,7 +432,8 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
    -
    print(R2(Energies,ytilde))
    +  
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
    +ytildenp = np.dot(fit,X.T)
     
    @@ -444,7 +449,7 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
    -

    We can easily add our MSE score as

    +

    And finally we plot our fit with and compare with data

    @@ -452,37 +457,18 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
    -
    def MSE(y_data,y_model):
    -    n = np.size(y_model)
    -    return np.sum((y_data-y_model)**2)/n
    -
    -print(MSE(Energies,ytilde))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    and finally the relative error as

    - - -
    -
    -
    -
    -
    -
    def RelativeError(y_data,y_model):
    -    return abs((y_data-y_model)/y_data)
    -print(RelativeError(Energies, ytilde))
    +  
    Masses['Eapprox']  = ytilde
    +# Generate a plot comparing the experimental with the fitted values values.
    +fig, ax = plt.subplots()
    +ax.set_xlabel(r'$A = N + Z$')
    +ax.set_ylabel(r'$E_\mathrm{bind}\,/\mathrm{MeV}$')
    +ax.plot(Masses['A'], Masses['Ebinding'], alpha=0.7, lw=2,
    +            label='Ame2016')
    +ax.plot(Masses['A'], Masses['Eapprox'], alpha=0.7, lw=2, c='m',
    +            label='Fit')
    +ax.legend()
    +save_fig("Masses2016OLS")
    +plt.show()
     
    @@ -524,7 +510,7 @@ Since we are not using Scikit-Learn here we can define our own \( R2 \) f
  • 31
  • 32
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs023.html b/doc/pub/week35/html/._week35-bs023.html index cbf192752..3cb23df82 100644 --- a/doc/pub/week35/html/._week35-bs023.html +++ b/doc/pub/week35/html/._week35-bs023.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,24 +393,111 @@ MathJax.Hub.Config({

     

     

     

    -

    Splitting our Data in Training and Test data

    +

    Adding error analysis and training set up

    -
    -
    - - -

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

    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

    + + +
    +
    +
    +
    +
    +
    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(Energies,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(Energies,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    and finally the relative error as

    + + +
    +
    +
    +
    +
    +
    def RelativeError(y_data,y_model):
    +    return abs((y_data-y_model)/y_data)
    +print(RelativeError(Energies, ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    @@ -437,7 +526,7 @@ but now splitting the data into a training set and a test set.
  • 32
  • 33
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs024.html b/doc/pub/week35/html/._week35-bs024.html index db70d660e..ef585ecc1 100644 --- a/doc/pub/week35/html/._week35-bs024.html +++ b/doc/pub/week35/html/._week35-bs024.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,66 +393,24 @@ MathJax.Hub.Config({

     

     

     

    -

    Examples

    +

    Splitting our Data in Training and Test data

    +
    +
    + - -
    -
    -
    -
    -
    -
    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 given polynomial
    -X = np.zeros((len(x),3))
    -X[:,0] = 1.0
    -X[:,1] = x
    -X[:,2] = x**2
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -# matrix inversion to find beta
    -beta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    -print(beta)
    -# and then make the prediction
    -ytilde = X_train @ beta
    -print("Training R2")
    -print(R2(y_train,ytilde))
    -print("Training MSE")
    -print(MSE(y_train,ytilde))
    -ypredict = X_test @ beta
    -print("Test R2")
    -print(R2(y_test,ypredict))
    -print("Test MSE")
    -print(MSE(y_test,ypredict))
    -
    +

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

    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    @@ -479,7 +439,7 @@ ypredict = X_test 33
  • 34
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs025.html b/doc/pub/week35/html/._week35-bs025.html index 7e7330168..6e902a073 100644 --- a/doc/pub/week35/html/._week35-bs025.html +++ b/doc/pub/week35/html/._week35-bs025.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,7 +393,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Making your own test-train splitting

    +

    Examples

    @@ -400,20 +402,44 @@ MathJax.Hub.Config({
    -
    # 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()
    +  
    import os
    +import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
     
    -    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:]
    +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
     
    -    return X_train, X_test, Y_train, Y_test
    +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 given polynomial
    +X = np.zeros((len(x),3))
    +X[:,0] = 1.0
    +X[:,1] = x
    +X[:,2] = x**2
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +# matrix inversion to find beta
    +beta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    +print(beta)
    +# and then make the prediction
    +ytilde = X_train @ beta
    +print("Training R2")
    +print(R2(y_train,ytilde))
    +print("Training MSE")
    +print(MSE(y_train,ytilde))
    +ypredict = X_test @ beta
    +print("Test R2")
    +print(R2(y_test,ypredict))
    +print("Test MSE")
    +print(MSE(y_test,ypredict))
     
    @@ -429,10 +455,6 @@ MathJax.Hub.Config({
    -

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

    @@ -459,7 +481,7 @@ normally recommend using the latter functionality.

  • 34
  • 35
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs026.html b/doc/pub/week35/html/._week35-bs026.html index 3a5ae4efc..a5e5b9756 100644 --- a/doc/pub/week35/html/._week35-bs026.html +++ b/doc/pub/week35/html/._week35-bs026.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -390,33 +392,50 @@ MathJax.Hub.Config({

     

     

     

    - -

    The Boston housing data example

    + +

    Making your own test-train splitting

    -

    The Boston housing -data set was originally a part of UCI Machine Learning Repository -and has been removed now. The data set is now included in Scikit-Learn's -library. There are 506 samples and 13 feature (predictor) variables -in this data set. The objective is to predict the value of prices of -the house using the features (predictors) listed here. + + +

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

    -

    The features/predictors are

    -
      -
    1. CRIM: Per capita crime rate by town
    2. -
    3. ZN: Proportion of residential land zoned for lots over 25000 square feet
    4. -
    5. INDUS: Proportion of non-retail business acres per town
    6. -
    7. CHAS: Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
    8. -
    9. NOX: Nitric oxide concentration (parts per 10 million)
    10. -
    11. RM: Average number of rooms per dwelling
    12. -
    13. AGE: Proportion of owner-occupied units built prior to 1940
    14. -
    15. DIS: Weighted distances to five Boston employment centers
    16. -
    17. RAD: Index of accessibility to radial highways
    18. -
    19. TAX: Full-value property tax rate per USD10000
    20. -
    21. B: \( 1000(Bk - 0.63)^2 \), where \( Bk \) is the proportion of [people of African American descent] by town
    22. -
    23. LSTAT: Percentage of lower status of the population
    24. -
    25. MEDV: Median value of owner-occupied homes in USD 1000s
    26. -

      @@ -442,7 +461,7 @@ the house using the features (predictors) listed here.
    • 35
    • 36
    • ...
    • -
    • 71
    • +
    • 72
    • »
    diff --git a/doc/pub/week35/html/._week35-bs027.html b/doc/pub/week35/html/._week35-bs027.html index cda46d6ca..1b47be7b4 100644 --- a/doc/pub/week35/html/._week35-bs027.html +++ b/doc/pub/week35/html/._week35-bs027.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -390,348 +392,33 @@ MathJax.Hub.Config({

     

     

     

    - -

    Housing data, the code

    -

    We start by importing the libraries

    - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import matplotlib.pyplot as plt 
    -
    -import pandas as pd  
    -import seaborn as sns 
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    and load the Boston Housing DataSet from Scikit-Learn

    - - - -
    -
    -
    -
    -
    -
    from sklearn.datasets import load_boston
    -
    -boston_dataset = load_boston()
    -
    -# boston_dataset is a dictionary
    -# let's check what it contains
    -boston_dataset.keys()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Then we invoke Pandas

    - - -
    -
    -
    -
    -
    -
    boston = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)
    -boston.head()
    -boston['MEDV'] = boston_dataset.target
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    and preprocess the data

    - - -
    -
    -
    -
    -
    -
    # check for missing values in all the columns
    -boston.isnull().sum()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    We can then visualize the data

    - - -
    -
    -
    -
    -
    -
    # set the size of the figure
    -sns.set(rc={'figure.figsize':(11.7,8.27)})
    -
    -# plot a histogram showing the distribution of the target values
    -sns.distplot(boston['MEDV'], bins=30)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    It is now useful to look at the correlation matrix

    - - -
    -
    -
    -
    -
    -
    # compute the pair wise correlation for all columns  
    -correlation_matrix = boston.corr().round(2)
    -# use the heatmap function from seaborn to plot the correlation matrix
    -# annot = True to print the values inside the square
    -sns.heatmap(data=correlation_matrix, annot=True)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    From the above coorelation plot we can see that MEDV is strongly correlated to LSTAT and RM. We see also that RAD and TAX are stronly correlated, but we don't include this in our features together to avoid multi-colinearity

    - - - -
    -
    -
    -
    -
    -
    plt.figure(figsize=(20, 5))
    -
    -features = ['LSTAT', 'RM']
    -target = boston['MEDV']
    -
    -for i, col in enumerate(features):
    -    plt.subplot(1, len(features) , i+1)
    -    x = boston[col]
    -    y = target
    -    plt.scatter(x, y, marker='o')
    -    plt.title(col)
    -    plt.xlabel(col)
    -    plt.ylabel('MEDV')
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Now we start training our model

    - - -
    -
    -
    -
    -
    -
    X = pd.DataFrame(np.c_[boston['LSTAT'], boston['RM']], columns = ['LSTAT','RM'])
    -Y = boston['MEDV']
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    We split the data into training and test sets

    - - - -
    -
    -
    -
    -
    -
    from sklearn.model_selection import train_test_split
    -
    -# splits the training and test data set in 80% : 20%
    -# assign random_state to any value.This ensures consistency.
    -X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=5)
    -print(X_train.shape)
    -print(X_test.shape)
    -print(Y_train.shape)
    -print(Y_test.shape)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Then we use the linear regression functionality from Scikit-Learn

    - - -
    -
    -
    -
    -
    -
    from sklearn.linear_model import LinearRegression
    -from sklearn.metrics import mean_squared_error, r2_score
    -
    -lin_model = LinearRegression()
    -lin_model.fit(X_train, Y_train)
    -
    -# model evaluation for training set
    -
    -y_train_predict = lin_model.predict(X_train)
    -rmse = (np.sqrt(mean_squared_error(Y_train, y_train_predict)))
    -r2 = r2_score(Y_train, y_train_predict)
    -
    -print("The model performance for training set")
    -print("--------------------------------------")
    -print('RMSE is {}'.format(rmse))
    -print('R2 score is {}'.format(r2))
    -print("\n")
    -
    -# model evaluation for testing set
    -
    -y_test_predict = lin_model.predict(X_test)
    -# root mean square error of the model
    -rmse = (np.sqrt(mean_squared_error(Y_test, y_test_predict)))
    -
    -# r-squared score of the model
    -r2 = r2_score(Y_test, y_test_predict)
    -
    -print("The model performance for testing set")
    -print("--------------------------------------")
    -print('RMSE is {}'.format(rmse))
    -print('R2 score is {}'.format(r2))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    # plotting the y_test vs y_pred
    -# ideally should have been a straight line
    -plt.scatter(Y_test, y_test_predict)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    + +

    The Boston housing data example

    +

    The Boston housing +data set was originally a part of UCI Machine Learning Repository +and has been removed now. The data set is now included in Scikit-Learn's +library. There are 506 samples and 13 feature (predictor) variables +in this data set. The objective is to predict the value of prices of +the house using the features (predictors) listed here. +

    +

    The features/predictors are

    +
      +
    1. CRIM: Per capita crime rate by town
    2. +
    3. ZN: Proportion of residential land zoned for lots over 25000 square feet
    4. +
    5. INDUS: Proportion of non-retail business acres per town
    6. +
    7. CHAS: Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
    8. +
    9. NOX: Nitric oxide concentration (parts per 10 million)
    10. +
    11. RM: Average number of rooms per dwelling
    12. +
    13. AGE: Proportion of owner-occupied units built prior to 1940
    14. +
    15. DIS: Weighted distances to five Boston employment centers
    16. +
    17. RAD: Index of accessibility to radial highways
    18. +
    19. TAX: Full-value property tax rate per USD10000
    20. +
    21. B: \( 1000(Bk - 0.63)^2 \), where \( Bk \) is the proportion of [people of African American descent] by town
    22. +
    23. LSTAT: Percentage of lower status of the population
    24. +
    25. MEDV: Median value of owner-occupied homes in USD 1000s
    26. +

    diff --git a/doc/pub/week35/html/._week35-bs028.html b/doc/pub/week35/html/._week35-bs028.html index da577dbbc..e78405f4e 100644 --- a/doc/pub/week35/html/._week35-bs028.html +++ b/doc/pub/week35/html/._week35-bs028.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,33 +393,344 @@ MathJax.Hub.Config({

     

     

     

    -

    Reducing the number of degrees of freedom, overarching view

    -
    -
    - +

    Housing data, the code

    +

    We start by importing the libraries

    -

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

    + +
    +
    +
    +
    +
    +
    import numpy as np
    +import matplotlib.pyplot as plt 
     
    -

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

    +import pandas as pd +import seaborn as sns +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    and load the Boston Housing DataSet from Scikit-Learn

    + + + +
    +
    +
    +
    +
    +
    from sklearn.datasets import load_boston
    +
    +boston_dataset = load_boston()
    +
    +# boston_dataset is a dictionary
    +# let's check what it contains
    +boston_dataset.keys()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Then we invoke Pandas

    + + +
    +
    +
    +
    +
    +
    boston = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)
    +boston.head()
    +boston['MEDV'] = boston_dataset.target
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    and preprocess the data

    + + +
    +
    +
    +
    +
    +
    # check for missing values in all the columns
    +boston.isnull().sum()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can then visualize the data

    + + +
    +
    +
    +
    +
    +
    # set the size of the figure
    +sns.set(rc={'figure.figsize':(11.7,8.27)})
    +
    +# plot a histogram showing the distribution of the target values
    +sns.distplot(boston['MEDV'], bins=30)
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    It is now useful to look at the correlation matrix

    + + +
    +
    +
    +
    +
    +
    # compute the pair wise correlation for all columns  
    +correlation_matrix = boston.corr().round(2)
    +# use the heatmap function from seaborn to plot the correlation matrix
    +# annot = True to print the values inside the square
    +sns.heatmap(data=correlation_matrix, annot=True)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    From the above coorelation plot we can see that MEDV is strongly correlated to LSTAT and RM. We see also that RAD and TAX are stronly correlated, but we don't include this in our features together to avoid multi-colinearity

    + + + +
    +
    +
    +
    +
    +
    plt.figure(figsize=(20, 5))
    +
    +features = ['LSTAT', 'RM']
    +target = boston['MEDV']
    +
    +for i, col in enumerate(features):
    +    plt.subplot(1, len(features) , i+1)
    +    x = boston[col]
    +    y = target
    +    plt.scatter(x, y, marker='o')
    +    plt.title(col)
    +    plt.xlabel(col)
    +    plt.ylabel('MEDV')
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Now we start training our model

    + + +
    +
    +
    +
    +
    +
    X = pd.DataFrame(np.c_[boston['LSTAT'], boston['RM']], columns = ['LSTAT','RM'])
    +Y = boston['MEDV']
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We split the data into training and test sets

    + + + +
    +
    +
    +
    +
    +
    from sklearn.model_selection import train_test_split
    +
    +# splits the training and test data set in 80% : 20%
    +# assign random_state to any value.This ensures consistency.
    +X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=5)
    +print(X_train.shape)
    +print(X_test.shape)
    +print(Y_train.shape)
    +print(Y_test.shape)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Then we use the linear regression functionality from Scikit-Learn

    + + +
    +
    +
    +
    +
    +
    from sklearn.linear_model import LinearRegression
    +from sklearn.metrics import mean_squared_error, r2_score
    +
    +lin_model = LinearRegression()
    +lin_model.fit(X_train, Y_train)
    +
    +# model evaluation for training set
    +
    +y_train_predict = lin_model.predict(X_train)
    +rmse = (np.sqrt(mean_squared_error(Y_train, y_train_predict)))
    +r2 = r2_score(Y_train, y_train_predict)
    +
    +print("The model performance for training set")
    +print("--------------------------------------")
    +print('RMSE is {}'.format(rmse))
    +print('R2 score is {}'.format(r2))
    +print("\n")
    +
    +# model evaluation for testing set
    +
    +y_test_predict = lin_model.predict(X_test)
    +# root mean square error of the model
    +rmse = (np.sqrt(mean_squared_error(Y_test, y_test_predict)))
    +
    +# r-squared score of the model
    +r2 = r2_score(Y_test, y_test_predict)
    +
    +print("The model performance for testing set")
    +print("--------------------------------------")
    +print('RMSE is {}'.format(rmse))
    +print('R2 score is {}'.format(r2))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    # plotting the y_test vs y_pred
    +# ideally should have been a straight line
    +plt.scatter(Y_test, y_test_predict)
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    @@ -446,7 +759,7 @@ visualization.
  • 37
  • 38
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs029.html b/doc/pub/week35/html/._week35-bs029.html index 0f5260319..75e89da6c 100644 --- a/doc/pub/week35/html/._week35-bs029.html +++ b/doc/pub/week35/html/._week35-bs029.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,26 +393,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Preprocessing our data

    +

    Reducing the number of degrees of freedom, overarching view

    -

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

    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.

    -

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

    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.

    @@ -441,7 +448,7 @@ the features in a way to avoid such outlier values.
  • 38
  • 39
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs030.html b/doc/pub/week35/html/._week35-bs030.html index 871c087cd..71d325d11 100644 --- a/doc/pub/week35/html/._week35-bs030.html +++ b/doc/pub/week35/html/._week35-bs030.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,19 +393,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Functionality in Scikit-Learn

    +

    Preprocessing our data

    +
    +
    + -

    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 +

    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.

    +

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

    +
    +
    + +

      @@ -429,7 +443,7 @@ ensures that all features are exactly between \( 0 \) and \( 1 \). The
    • 39
    • 40
    • ...
    • -
    • 71
    • +
    • 72
    • »
    diff --git a/doc/pub/week35/html/._week35-bs031.html b/doc/pub/week35/html/._week35-bs031.html index db80db56d..f71b6150a 100644 --- a/doc/pub/week35/html/._week35-bs031.html +++ b/doc/pub/week35/html/._week35-bs031.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,33 +393,19 @@ MathJax.Hub.Config({

     

     

     

    -

    More preprocessing

    +

    Functionality in Scikit-Learn

    -
    -
    - -

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

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

    -
    -
    - -

    diff --git a/doc/pub/week35/html/._week35-bs032.html b/doc/pub/week35/html/._week35-bs032.html index dd530f5ed..1afa26592 100644 --- a/doc/pub/week35/html/._week35-bs032.html +++ b/doc/pub/week35/html/._week35-bs032.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,19 +393,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Frequently used scaling functions

    +

    More preprocessing

    -

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

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

    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.

    +
    +
    +

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

  • 41
  • 42
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs033.html b/doc/pub/week35/html/._week35-bs033.html index 3e81b322c..611ad45d7 100644 --- a/doc/pub/week35/html/._week35-bs033.html +++ b/doc/pub/week35/html/._week35-bs033.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,60 +393,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Example of own Standard scaling

    +

    Frequently used scaling functions

    -

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

    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:

    +$$ + x_j^{(i)} \rightarrow \frac{x_j^{(i)} - \overline{x}_j}{\sigma(x_j)}, +$$ - -
    -
    -
    -
    -
    -
    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 \( \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. +

    @@ -471,7 +432,7 @@ display(XPandas-Xscaled)

  • 42
  • 43
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs034.html b/doc/pub/week35/html/._week35-bs034.html index 6e39bd03b..7ea664689 100644 --- a/doc/pub/week35/html/._week35-bs034.html +++ b/doc/pub/week35/html/._week35-bs034.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,19 +393,60 @@ MathJax.Hub.Config({

     

     

     

    -

    Min-Max Scaling

    +

    Example of own Standard scaling

    -

    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 +

    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 (b-a)\frac{x_j^{(i)} - \min(x_j)}{\max(x_j) - \min(x_j)} - a -$$ -

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

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

    @@ -430,7 +473,7 @@ $$

  • 43
  • 44
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs035.html b/doc/pub/week35/html/._week35-bs035.html index 424f26ee8..dbfa64a4e 100644 --- a/doc/pub/week35/html/._week35-bs035.html +++ b/doc/pub/week35/html/._week35-bs035.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,102 +393,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Testing the Means Squared Error as function of Complexity

    -

    One of -the aims is to reproduce Figure 2.11 of Hastie et al. -We will also use Ridge and Lasso regression. +

    Min-Max Scaling

    + +

    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

    -

    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 fifth-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, Ridge, Lasso
    -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()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +$$ +x_j^{(i)} \rightarrow (b-a)\frac{x_j^{(i)} - \min(x_j)}{\max(x_j) - \min(x_j)} - a +$$ +

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

    @@ -513,7 +432,7 @@ plt.show()

  • 44
  • 45
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs036.html b/doc/pub/week35/html/._week35-bs036.html index 9020e07e1..34cddb168 100644 --- a/doc/pub/week35/html/._week35-bs036.html +++ b/doc/pub/week35/html/._week35-bs036.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,8 +393,13 @@ MathJax.Hub.Config({

     

     

     

    -

    More preprocessing examples, Franke function and regression

    +

    Testing the Means Squared Error as function of Complexity

    +

    One of +the aims is to reproduce Figure 2.11 of Hastie et al. +We will also use Ridge and Lasso regression. +

    +

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

    @@ -400,98 +407,73 @@ MathJax.Hub.Config({
    -
    # Common imports
    -import os
    +  
    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 fifth-order polynomial. Scale your data and split it in training and test data.

    + + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -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
    -
    -# Where to save the figures and data files
    -PROJECT_ROOT_DIR = "Results"
    -FIGURE_ID = "Results/FigureFiles"
    -DATA_ID = "DataFiles/"
    -
    -if not os.path.exists(PROJECT_ROOT_DIR):
    -    os.mkdir(PROJECT_ROOT_DIR)
    -
    -if not os.path.exists(FIGURE_ID):
    -    os.makedirs(FIGURE_ID)
    -
    -if not os.path.exists(DATA_ID):
    -    os.makedirs(DATA_ID)
    -
    -def image_path(fig_id):
    -    return os.path.join(FIGURE_ID, fig_id)
    -
    -def data_path(dat_id):
    -    return os.path.join(DATA_ID, dat_id)
    -
    -def save_fig(fig_id):
    -    plt.savefig(image_path(fig_id) + ".png", format='png')
    +from sklearn.linear_model import LinearRegression, Ridge, Lasso
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.model_selection import train_test_split
    +from sklearn.pipeline import make_pipeline
     
     
    -def FrankeFunction(x,y):
    -	term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
    -	term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
    -	term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
    -	term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
    -	return term1 + term2 + term3 + term4
    -
    -
    -def create_X(x, y, n ):
    -	if len(x.shape) > 1:
    -		x = np.ravel(x)
    -		y = np.ravel(y)
    -
    -	N = len(x)
    -	l = int((n+1)*(n+2)/2)		# Number of elements in beta
    -	X = np.ones((N,l))
    -
    -	for i in range(1,n+1):
    -		q = int((i)*(i+1)/2)
    -		for k in range(i+1):
    -			X[:,q+k] = (x**(i-k))*(y**k)
    -
    -	return X
    -
    -
    -# Making meshgrid of datapoints and compute Franke's function
    -n = 5
    -N = 1000
    -x = np.sort(np.random.uniform(0, 1, N))
    -y = np.sort(np.random.uniform(0, 1, N))
    -z = FrankeFunction(x, y)
    -X = create_X(x, y, n=n)    
    -# split in training and test data
    -X_train, X_test, y_train, y_test = train_test_split(X,z,test_size=0.2)
    -
    -
    -clf = skl.LinearRegression().fit(X_train, y_train)
    -
    -# The mean squared error and R2 score
    -print("MSE before scaling: {:.2f}".format(mean_squared_error(clf.predict(X_test), y_test)))
    -print("R2 score before scaling {:.2f}".format(clf.score(X_test,y_test)))
    -
    +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)
    +scaler.fit(x_train)
    +x_train_scaled = scaler.transform(x_train)
    +x_test_scaled = scaler.transform(x_test)
     
    -print("Feature min values before scaling:\n {}".format(X_train.min(axis=0)))
    -print("Feature max values before scaling:\n {}".format(X_train.max(axis=0)))
    +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) )
     
    -print("Feature min values after scaling:\n {}".format(X_train_scaled.min(axis=0)))
    -print("Feature max values after scaling:\n {}".format(X_train_scaled.max(axis=0)))
    -
    -clf = skl.LinearRegression().fit(X_train_scaled, y_train)
    -
    -
    -print("MSE after  scaling: {:.2f}".format(mean_squared_error(clf.predict(X_test_scaled), y_test)))
    -print("R2 score for  scaled data: {:.2f}".format(clf.score(X_test_scaled,y_test)))
    +plt.plot(polydegree, TestError, label='Test Error')
    +plt.plot(polydegree, TrainError, label='Train Error')
    +plt.legend()
    +plt.show()
     
    @@ -533,7 +515,7 @@ clf = skl.45
  • 46
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs037.html b/doc/pub/week35/html/._week35-bs037.html index b04ff1808..585bccdc3 100644 --- a/doc/pub/week35/html/._week35-bs037.html +++ b/doc/pub/week35/html/._week35-bs037.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,7 +393,122 @@ MathJax.Hub.Config({

     

     

     

    -

    Material for lecture Thursday, August 31

    +

    More preprocessing examples, Franke function and regression

    + + + +
    +
    +
    +
    +
    +
    # Common imports
    +import os
    +import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +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
    +
    +# Where to save the figures and data files
    +PROJECT_ROOT_DIR = "Results"
    +FIGURE_ID = "Results/FigureFiles"
    +DATA_ID = "DataFiles/"
    +
    +if not os.path.exists(PROJECT_ROOT_DIR):
    +    os.mkdir(PROJECT_ROOT_DIR)
    +
    +if not os.path.exists(FIGURE_ID):
    +    os.makedirs(FIGURE_ID)
    +
    +if not os.path.exists(DATA_ID):
    +    os.makedirs(DATA_ID)
    +
    +def image_path(fig_id):
    +    return os.path.join(FIGURE_ID, fig_id)
    +
    +def data_path(dat_id):
    +    return os.path.join(DATA_ID, dat_id)
    +
    +def save_fig(fig_id):
    +    plt.savefig(image_path(fig_id) + ".png", format='png')
    +
    +
    +def FrankeFunction(x,y):
    +	term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
    +	term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
    +	term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
    +	term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
    +	return term1 + term2 + term3 + term4
    +
    +
    +def create_X(x, y, n ):
    +	if len(x.shape) > 1:
    +		x = np.ravel(x)
    +		y = np.ravel(y)
    +
    +	N = len(x)
    +	l = int((n+1)*(n+2)/2)		# Number of elements in beta
    +	X = np.ones((N,l))
    +
    +	for i in range(1,n+1):
    +		q = int((i)*(i+1)/2)
    +		for k in range(i+1):
    +			X[:,q+k] = (x**(i-k))*(y**k)
    +
    +	return X
    +
    +
    +# Making meshgrid of datapoints and compute Franke's function
    +n = 5
    +N = 1000
    +x = np.sort(np.random.uniform(0, 1, N))
    +y = np.sort(np.random.uniform(0, 1, N))
    +z = FrankeFunction(x, y)
    +X = create_X(x, y, n=n)    
    +# split in training and test data
    +X_train, X_test, y_train, y_test = train_test_split(X,z,test_size=0.2)
    +
    +
    +clf = skl.LinearRegression().fit(X_train, y_train)
    +
    +# The mean squared error and R2 score
    +print("MSE before scaling: {:.2f}".format(mean_squared_error(clf.predict(X_test), y_test)))
    +print("R2 score before scaling {:.2f}".format(clf.score(X_test,y_test)))
    +
    +scaler = StandardScaler()
    +scaler.fit(X_train)
    +X_train_scaled = scaler.transform(X_train)
    +X_test_scaled = scaler.transform(X_test)
    +
    +print("Feature min values before scaling:\n {}".format(X_train.min(axis=0)))
    +print("Feature max values before scaling:\n {}".format(X_train.max(axis=0)))
    +
    +print("Feature min values after scaling:\n {}".format(X_train_scaled.min(axis=0)))
    +print("Feature max values after scaling:\n {}".format(X_train_scaled.max(axis=0)))
    +
    +clf = skl.LinearRegression().fit(X_train_scaled, y_train)
    +
    +
    +print("MSE after  scaling: {:.2f}".format(mean_squared_error(clf.predict(X_test_scaled), y_test)))
    +print("R2 score for  scaled data: {:.2f}".format(clf.score(X_test_scaled,y_test)))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -418,7 +535,7 @@ MathJax.Hub.Config({

  • 46
  • 47
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs038.html b/doc/pub/week35/html/._week35-bs038.html index 8a9252f19..53f23a59f 100644 --- a/doc/pub/week35/html/._week35-bs038.html +++ b/doc/pub/week35/html/._week35-bs038.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,37 +393,7 @@ 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 \( \beta \) are given by

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

    The hat over \( \boldsymbol{\beta} \) 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{\beta}} = \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{\beta}} = \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. -

    +

    Material for lecture Thursday, August 31

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

  • 47
  • 48
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs039.html b/doc/pub/week35/html/._week35-bs039.html index f0055b02b..fe3293690 100644 --- a/doc/pub/week35/html/._week35-bs039.html +++ b/doc/pub/week35/html/._week35-bs039.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,14 +393,37 @@ MathJax.Hub.Config({

     

     

     

    -

    Residual Error

    +

    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 \( \beta \) are given by

    -

    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}. +\hat{\boldsymbol{\beta}} = \left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$ -

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

    +

    The hat over \( \boldsymbol{\beta} \) 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{\beta}} = \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{\beta}} = \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. +

    @@ -425,7 +450,7 @@ $$

  • 48
  • 49
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs040.html b/doc/pub/week35/html/._week35-bs040.html index bb1150395..30146ed98 100644 --- a/doc/pub/week35/html/._week35-bs040.html +++ b/doc/pub/week35/html/._week35-bs040.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,25 +393,14 @@ MathJax.Hub.Config({

     

     

     

    -

    Simple case

    - -

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

    +

    Residual Error

    +

    We have defined the residual error as

    $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{X}\boldsymbol{X}^T = \boldsymbol{I}. +\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}. $$ -

    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.

    +

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

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

  • 49
  • 50
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs041.html b/doc/pub/week35/html/._week35-bs041.html index d564e8d1c..0c9599873 100644 --- a/doc/pub/week35/html/._week35-bs041.html +++ b/doc/pub/week35/html/._week35-bs041.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,49 +393,25 @@ MathJax.Hub.Config({

     

     

     

    -

    The singular value decomposition

    +

    Simple case

    -
    -
    - +

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

    -

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

    +$$ +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{X}\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. -

    +

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

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

    -
    -
    +

    and we have the obvious case

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

    This serves also as a useful test of our codes.

    @@ -460,7 +438,7 @@ reduced to the statistically relevant features.

  • 50
  • 51
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs042.html b/doc/pub/week35/html/._week35-bs042.html index 3edf63337..01217c18c 100644 --- a/doc/pub/week35/html/._week35-bs042.html +++ b/doc/pub/week35/html/._week35-bs042.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,55 +393,50 @@ MathJax.Hub.Config({

     

     

     

    -

    Linear Regression Problems

    +

    The singular value decomposition

    -

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

    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.

    -

    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 +

    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.

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

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

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

    +
    +
    + +

      @@ -465,7 +462,7 @@ This is equivalent to saying that the matrix \( \boldsymbol{X} \) has at least a
    • 51
    • 52
    • ...
    • -
    • 71
    • +
    • 72
    • »
    diff --git a/doc/pub/week35/html/._week35-bs043.html b/doc/pub/week35/html/._week35-bs043.html index 411ae1d4b..2def4661a 100644 --- a/doc/pub/week35/html/._week35-bs043.html +++ b/doc/pub/week35/html/._week35-bs043.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,29 +393,54 @@ MathJax.Hub.Config({

     

     

     

    -

    Fixing the singularity

    +

    Linear Regression Problems

    -

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

    +

    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} -\boldsymbol{\beta} & = (\boldsymbol{X}^{T} \boldsymbol{X})^{-1} \boldsymbol{X}^{T} \boldsymbol{y}, -\tag{1} -\end{align} +\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*} $$ -

    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) \( \beta_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 \( \beta_i \) cannot be estimated. +

    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.

    -

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

    +

    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 +

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

    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.

    +

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

    @@ -440,7 +467,7 @@ $$

  • 52
  • 53
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs044.html b/doc/pub/week35/html/._week35-bs044.html index 0248c7bd3..b161d8f0d 100644 --- a/doc/pub/week35/html/._week35-bs044.html +++ b/doc/pub/week35/html/._week35-bs044.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,41 +393,29 @@ MathJax.Hub.Config({

     

     

     

    -

    Basic math of the SVD

    +

    Fixing the singularity

    -

    From standard linear algebra we know that a square matrix \( \boldsymbol{X} \) can be diagonalized if and only 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 +

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

    +$$ +\begin{align} +\boldsymbol{\beta} & = (\boldsymbol{X}^{T} \boldsymbol{X})^{-1} \boldsymbol{X}^{T} \boldsymbol{y}, +\tag{1} +\end{align} +$$ + +

    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) \( \beta_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 \( \beta_i \) cannot be estimated.

    +

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

    $$ -(\lambda_1,\boldsymbol{u}_1),\dots, (\lambda_n,\boldsymbol{u}_n), +\boldsymbol{X}^{T} \boldsymbol{X} \rightarrow \boldsymbol{X}^{T} \boldsymbol{X}+\lambda \boldsymbol{I}, $$ -

    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, -$$ - -

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

    +

    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.

    @@ -452,7 +442,7 @@ $$

  • 53
  • 54
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs045.html b/doc/pub/week35/html/._week35-bs045.html index 75cd0ab9b..4def352cf 100644 --- a/doc/pub/week35/html/._week35-bs045.html +++ b/doc/pub/week35/html/._week35-bs045.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,52 +393,41 @@ MathJax.Hub.Config({

     

     

     

    -

    The SVD, a Fantastic Algorithm

    +

    Basic math of the 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 +

    From standard linear algebra we know that a square matrix \( \boldsymbol{X} \) can be diagonalized if and only 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

    -$$ -\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, +(\lambda_1,\boldsymbol{u}_1),\dots, (\lambda_n,\boldsymbol{u}_n), $$ -

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

    +

    and the eigenvalues are given by the diagonal matrix

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

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

    +

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

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

    +

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

    -

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

    +

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

    @@ -463,7 +454,7 @@ near singular or singular matrices.

  • 54
  • 55
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs046.html b/doc/pub/week35/html/._week35-bs046.html index 498c28395..7c7c12a48 100644 --- a/doc/pub/week35/html/._week35-bs046.html +++ b/doc/pub/week35/html/._week35-bs046.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,28 +393,53 @@ MathJax.Hub.Config({

     

     

     

    -

    Economy-size SVD

    +

    The SVD, a Fantastic Algorithm

    -

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

    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

    -

    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. +$$ +\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!

    -

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

    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.

    +

      @@ -438,7 +465,7 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
    • 55
    • 56
    • ...
    • -
    • 71
    • +
    • 72
    • »
    diff --git a/doc/pub/week35/html/._week35-bs047.html b/doc/pub/week35/html/._week35-bs047.html index 2483a8e93..354e34ba6 100644 --- a/doc/pub/week35/html/._week35-bs047.html +++ b/doc/pub/week35/html/._week35-bs047.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,67 +393,26 @@ MathJax.Hub.Config({

     

     

     

    -

    Codes for the SVD

    +

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

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

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

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

    @@ -479,7 +440,7 @@ in the program terminating due to a singular matrix.

  • 56
  • 57
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs048.html b/doc/pub/week35/html/._week35-bs048.html index d2459b164..fc696d27b 100644 --- a/doc/pub/week35/html/._week35-bs048.html +++ b/doc/pub/week35/html/._week35-bs048.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,22 +393,67 @@ MathJax.Hub.Config({

     

     

     

    -

    Note about SVD Calculations

    +

    Codes for the SVD

    -

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

    -

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

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

    @@ -434,7 +481,7 @@ example

  • 57
  • 58
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs049.html b/doc/pub/week35/html/._week35-bs049.html index 33801fb72..a7cf07281 100644 --- a/doc/pub/week35/html/._week35-bs049.html +++ b/doc/pub/week35/html/._week35-bs049.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,38 +393,23 @@ MathJax.Hub.Config({

     

     

     

    -

    Mathematics of the SVD and implications

    +

    Note about SVD Calculations

    -

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

    +

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

    -

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

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

    -

    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.

    +

    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 +

    @@ -449,7 +436,7 @@ $$

  • 58
  • 59
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs050.html b/doc/pub/week35/html/._week35-bs050.html index 50865770b..82873a828 100644 --- a/doc/pub/week35/html/._week35-bs050.html +++ b/doc/pub/week35/html/._week35-bs050.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,62 +393,38 @@ MathJax.Hub.Config({

     

     

     

    -

    Example Matrix

    +

    Mathematics of the SVD and implications

    -

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

    +

    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{\Sigma}= -\begin{bmatrix} -2& 0 \\ -0 & 1 \\ -0 & 0 \\ -\end{bmatrix} +\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 singular values are \( \sigma_0=2 \) and \( \sigma_1=1 \). It is common to rewrite the matrix \( \boldsymbol{\Sigma} \) as

    - +

    We can SVD decompose our matrix as

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

    where

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

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

    -

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

    +

    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

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

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

    +

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

    @@ -473,7 +451,7 @@ decomposition of the design matrix.

  • 59
  • 60
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs051.html b/doc/pub/week35/html/._week35-bs051.html index 61250fd26..248e2d307 100644 --- a/doc/pub/week35/html/._week35-bs051.html +++ b/doc/pub/week35/html/._week35-bs051.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,45 +393,61 @@ MathJax.Hub.Config({

     

     

     

    -

    Setting up the Matrix to be inverted

    +

    Example Matrix

    -

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

    +

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

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

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

    +

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

    $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^T. +\boldsymbol{\Sigma}= +\begin{bmatrix} +\boldsymbol{\tilde{\Sigma}}\\ +\boldsymbol{0}\\ +\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 \).

    - -

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

    - +

    where

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

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

    +

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

    $$ -\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{\Sigma}^T\boldsymbol{\Sigma}= +\begin{bmatrix} +4& 0 \\ +0 & 1 \\ +\end{bmatrix}, $$ -

    which gives us, using the orthogonality of the matrices \( \boldsymbol{U} \) and \( \boldsymbol{V} \),

    - +

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

    $$ -\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}, +\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T= +\begin{bmatrix} +4& 0 & 0\\ +0 & 1 & 0\\ +0 & 0 & 0\\ +\end{bmatrix}, $$ -

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

    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.

    @@ -457,7 +475,7 @@ that is \( \boldsymbol{\tilde{y}}\ne \boldsymbol{y} \).

  • 60
  • 61
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs052.html b/doc/pub/week35/html/._week35-bs052.html index c86644a2e..7b133ab5a 100644 --- a/doc/pub/week35/html/._week35-bs052.html +++ b/doc/pub/week35/html/._week35-bs052.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,52 +393,45 @@ MathJax.Hub.Config({

     

     

     

    -

    Further properties (important for our analyses later)

    +

    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

    -

    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. +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{U}^T\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T, $$ -

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

    +

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

    + $$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{V}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}. +\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\boldsymbol{\Sigma}^T\boldsymbol{\Sigma}\boldsymbol{V}^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 -

    +

    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

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

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

    +

    and using our SVD decomposition of \( \boldsymbol{X} \) 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. +\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}, $$ -

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

    +

    which gives us, using the orthogonality of the matrices \( \boldsymbol{U} \) and \( \boldsymbol{V} \),

    + $$ -\left(\boldsymbol{X}\boldsymbol{X}^T\right)\boldsymbol{U}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^T. +\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}, $$ -

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

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

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

  • 61
  • 62
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs053.html b/doc/pub/week35/html/._week35-bs053.html index 53519a187..0d4142570 100644 --- a/doc/pub/week35/html/._week35-bs053.html +++ b/doc/pub/week35/html/._week35-bs053.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,31 +393,52 @@ MathJax.Hub.Config({

     

     

     

    -

    Meet the Covariance Matrix

    +

    Further properties (important for our analyses later)

    -

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

    +

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

    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 +

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

    -$$ -\frac{\partial^2 C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}^T\partial \boldsymbol{\beta}} =\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. +

    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.

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

  • 62
  • 63
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs054.html b/doc/pub/week35/html/._week35-bs054.html index a6431c9c7..9aed8bc3c 100644 --- a/doc/pub/week35/html/._week35-bs054.html +++ b/doc/pub/week35/html/._week35-bs054.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,46 +393,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Introducing the Covariance and Correlation functions

    +

    Meet the Covariance 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. +

    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

    -

    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}] \\ - \end{bmatrix}, +\frac{\partial^2 C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}^T\partial \boldsymbol{\beta}} =\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. $$ -

    where for example

    +

    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

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

    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 calculate the covariance, this -quantity will be computed with a factor \( 1/(n-1) \). +

    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.

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

  • 63
  • 64
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs055.html b/doc/pub/week35/html/._week35-bs055.html index 92d62e583..d59a6bdb0 100644 --- a/doc/pub/week35/html/._week35-bs055.html +++ b/doc/pub/week35/html/._week35-bs055.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,32 +393,47 @@ MathJax.Hub.Config({

     

     

     

    -

    Covariance and Correlation Matrix

    +

    Introducing the Covariance and Correlation functions

    -

    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 +

    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.

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

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

    - $$ -\boldsymbol{K}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \\ - \mathrm{corr}[\boldsymbol{y},\boldsymbol{x}] & 1 \\ +\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}, $$ -

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

    +

    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 calculate the covariance, this +quantity will be computed with a factor \( 1/(n-1) \). +

    @@ -443,7 +460,7 @@ $$

  • 64
  • 65
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs056.html b/doc/pub/week35/html/._week35-bs056.html index dae40d18b..d2d30a7e3 100644 --- a/doc/pub/week35/html/._week35-bs056.html +++ b/doc/pub/week35/html/._week35-bs056.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,65 +393,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Function and Design/Feature Matrix

    +

    Covariance and Correlation Matrix

    -

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

    $$ -\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}, +\mathrm{corr}[\boldsymbol{x},\boldsymbol{y}]=\frac{\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{\mathrm{var}[\boldsymbol{x}] \mathrm{var}[\boldsymbol{y}]}}. $$ -

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

    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{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}, +\boldsymbol{K}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \\ + \mathrm{corr}[\boldsymbol{y},\boldsymbol{x}] & 1 \\ + \end{bmatrix}, $$ +

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

    @@ -476,7 +445,7 @@ $$

  • 65
  • 66
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs057.html b/doc/pub/week35/html/._week35-bs057.html index 3b95aee16..015354546 100644 --- a/doc/pub/week35/html/._week35-bs057.html +++ b/doc/pub/week35/html/._week35-bs057.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,60 +393,64 @@ MathJax.Hub.Config({

     

     

     

    -

    Covariance Matrix Examples

    +

    Correlation Function and Design/Feature 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} \) +

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

    -

    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}, +\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}, $$ -

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

    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{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}, +$$ - -
    -
    -
    -
    -
    -
    # 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)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

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

    @@ -472,7 +478,7 @@ C = np.c

  • 66
  • 67
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs058.html b/doc/pub/week35/html/._week35-bs058.html index 808b5e8b5..5566b7b72 100644 --- a/doc/pub/week35/html/._week35-bs058.html +++ b/doc/pub/week35/html/._week35-bs058.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,13 +393,27 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Matrix

    +

    Covariance Matrix Examples

    -

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

    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.

    @@ -407,26 +423,15 @@ a more brute force way. Here we scale the mean values for each column of the des
    -
    import numpy as np
    +  
    # Importing various packages
    +import numpy as np
     n = 100
    -# define two vectors                                                                                           
    -x = np.random.random(size=n)
    +x = np.random.normal(size=n)
    +print(np.mean(x))
     y = 4+3*x+np.random.normal(size=n)
    -#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(np.mean(y))
    +W = np.vstack((x, y))
    +C = np.cov(W)
     print(C)
     
    @@ -443,12 +448,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.

    @@ -475,7 +474,7 @@ this matrix we easily see that it is a positive definite matrix.

  • 67
  • 68
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs059.html b/doc/pub/week35/html/._week35-bs059.html index 619fea4c0..f542ce8b4 100644 --- a/doc/pub/week35/html/._week35-bs059.html +++ b/doc/pub/week35/html/._week35-bs059.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,9 +393,15 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Matrix with Pandas

    +

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

    -

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

    @@ -402,19 +410,26 @@ MathJax.Hub.Config({
    import numpy as np
    -import pandas as pd
    -n = 10
    -x = np.random.normal(size=n)
    -x = x - np.mean(x)
    +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                                                                                   
    +x = x - np.mean(x)
     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)
    +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)
     
    @@ -430,7 +445,12 @@ correlation_matrix = Xpd= Xpd68
  • 69
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs060.html b/doc/pub/week35/html/._week35-bs060.html index 5c51da739..acdb28a3d 100644 --- a/doc/pub/week35/html/._week35-bs060.html +++ b/doc/pub/week35/html/._week35-bs060.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,8 +393,9 @@ MathJax.Hub.Config({

     

     

     

    -

    Correlation Matrix with Pandas and the Franke function

    +

    Correlation Matrix with Pandas

    +

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

    @@ -400,49 +403,20 @@ MathJax.Hub.Config({
    -
    # Common imports
    -import numpy as np
    +  
    import numpy as np
     import pandas as pd
    -
    -
    -def FrankeFunction(x,y):
    -	term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
    -	term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
    -	term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
    -	term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
    -	return term1 + term2 + term3 + term4
    -
    -
    -def create_X(x, y, n ):
    -	if len(x.shape) > 1:
    -		x = np.ravel(x)
    -		y = np.ravel(y)
    -
    -	N = len(x)
    -	l = int((n+1)*(n+2)/2)		# Number of elements in beta
    -	X = np.ones((N,l))
    -
    -	for i in range(1,n+1):
    -		q = int((i)*(i+1)/2)
    -		for k in range(i+1):
    -			X[:,q+k] = (x**(i-k))*(y**k)
    -
    -	return X
    -
    -
    -# Making meshgrid of datapoints and compute Franke's function
    -n = 4
    -N = 100
    -x = np.sort(np.random.uniform(0, 1, N))
    -y = np.sort(np.random.uniform(0, 1, N))
    -z = FrankeFunction(x, y)
    -X = create_X(x, y, n=n)    
    -
    +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)
    -# subtract the mean values and set up the covariance matrix
    -Xpd = Xpd - Xpd.mean()
    -covariance_matrix = Xpd.cov()
    -print(covariance_matrix)
    +print(Xpd)
    +correlation_matrix = Xpd.corr()
    +print(correlation_matrix)
     
    @@ -458,16 +432,7 @@ covariance_matrix = Xpd69
  • 70
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs061.html b/doc/pub/week35/html/._week35-bs061.html index be2fe7e5c..a86be3b75 100644 --- a/doc/pub/week35/html/._week35-bs061.html +++ b/doc/pub/week35/html/._week35-bs061.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,41 +393,83 @@ MathJax.Hub.Config({

     

     

     

    -

    Rewriting the Covariance and/or Correlation Matrix

    +

    Correlation Matrix with Pandas and the Franke function

    -

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

    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}. -$$ + +
    +
    +
    +
    +
    +
    # Common imports
    +import numpy as np
    +import pandas as pd
     
    -

    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}, -$$ +def FrankeFunction(x,y): + term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2)) + term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1)) + term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2)) + term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2) + return term1 + term2 + term3 + term4 -

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

    +def create_X(x, y, n ): + if len(x.shape) > 1: + x = np.ravel(x) + y = np.ravel(y) + + N = len(x) + l = int((n+1)*(n+2)/2) # Number of elements in beta + X = np.ones((N,l)) + + for i in range(1,n+1): + q = int((i)*(i+1)/2) + for k in range(i+1): + X[:,q+k] = (x**(i-k))*(y**k) + + return X + + +# Making meshgrid of datapoints and compute Franke's function +n = 4 +N = 100 +x = np.sort(np.random.uniform(0, 1, N)) +y = np.sort(np.random.uniform(0, 1, N)) +z = FrankeFunction(x, y) +X = create_X(x, y, n=n) + +Xpd = pd.DataFrame(X) +# subtract the mean values and set up the covariance matrix +Xpd = Xpd - Xpd.mean() +covariance_matrix = Xpd.cov() +print(covariance_matrix) +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We note here that the covariance is zero for the first rows and +columns since all matrix elements in the design matrix were set to one +(we are fitting the function in terms of a polynomial of degree \( n \)). +

    + +

    This means that the variance for these elements will be zero and will +cause problems when we set up the correlation matrix. We can simply +drop these elements and construct a correlation +matrix without these elements. +

    @@ -451,6 +495,8 @@ $$

  • 69
  • 70
  • 71
  • +
  • ...
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs062.html b/doc/pub/week35/html/._week35-bs062.html index f79c2719e..2a87cab93 100644 --- a/doc/pub/week35/html/._week35-bs062.html +++ b/doc/pub/week35/html/._week35-bs062.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,39 +393,41 @@ MathJax.Hub.Config({

     

     

     

    -

    Linking with the SVD

    +

    Rewriting the Covariance and/or Correlation Matrix

    -

    We saw earlier that

    +

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

    $$ -\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. +\boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}= \mathbb{E}[\boldsymbol{X}^T\boldsymbol{X}]. $$ -

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

    +

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

    $$ -\boldsymbol{\Sigma}^T\boldsymbol{\Sigma} = \begin{bmatrix} \tilde{\boldsymbol{\Sigma}} & \boldsymbol{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\boldsymbol{\Sigma}} \\ \boldsymbol{0}\\ \end{bmatrix}, +\boldsymbol{X}=\begin{bmatrix} +x_{00} & x_{01}\\ +x_{10} & x_{11}\\ +\end{bmatrix}=\begin{bmatrix} +\boldsymbol{x}_{0} & \boldsymbol{x}_{1}\\ +\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

    - +

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

    $$ -\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} \\ +\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}, $$ -

    meaning we can write

    +

    which is just

    $$ -\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{V}\tilde{\boldsymbol{\Sigma}}^2\boldsymbol{V}^T. +\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}, $$ -

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

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

    @@ -448,6 +452,7 @@ $$

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs063.html b/doc/pub/week35/html/._week35-bs063.html index 426d246a9..47e35ab51 100644 --- a/doc/pub/week35/html/._week35-bs063.html +++ b/doc/pub/week35/html/._week35-bs063.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,45 +393,39 @@ MathJax.Hub.Config({

     

     

     

    -

    What does it mean?

    - -

    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 -

    +

    Linking with the SVD

    +

    We saw earlier that

    $$ -\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. +\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. $$ -

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

    - -

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

    - +

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

    $$ -\boldsymbol{C}[\boldsymbol{X}]=\frac{1}{n}\boldsymbol{X}^T\boldsymbol{X}, +\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

    + +$$ +\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}, +$$ + +

    meaning we can write

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

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

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

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs064.html b/doc/pub/week35/html/._week35-bs064.html index fb422c4d7..a5d16cd2a 100644 --- a/doc/pub/week35/html/._week35-bs064.html +++ b/doc/pub/week35/html/._week35-bs064.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,38 +393,44 @@ MathJax.Hub.Config({

     

     

     

    -

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

    +

    What does it mean?

    -

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

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

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

    -$$ -\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}, -$$ - -

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

    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

    -

    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} \). +$$ +\left(\boldsymbol{X}^T\boldsymbol{X}\right)\boldsymbol{v}_i=\boldsymbol{v}_i\sigma_i^2. +$$ + +

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

    + +

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

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

    @@ -446,6 +454,7 @@ values and the column vectors of \( \boldsymbol{V} \).

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs065.html b/doc/pub/week35/html/._week35-bs065.html index b086d03b0..e0653bbf4 100644 --- a/doc/pub/week35/html/._week35-bs065.html +++ b/doc/pub/week35/html/._week35-bs065.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,60 +393,40 @@ MathJax.Hub.Config({

     

     

     

    -

    Ridge and LASSO Regression

    +

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

    + +

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

    -

    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{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. +\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. $$ -

    or we can state it as

    +

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

    $$ -{\displaystyle \min_{\boldsymbol{\beta}\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{\beta}\vert\vert_2^2, +\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}, $$ -

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

    +

    leading to

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

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

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

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

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

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

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

    we have a new optimization equation

    -$$ -{\displaystyle \min_{\boldsymbol{\beta}\in -{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\beta}\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. -$$ - -

    diff --git a/doc/pub/week35/html/._week35-bs066.html b/doc/pub/week35/html/._week35-bs066.html index 9709aa90c..c8a273264 100644 --- a/doc/pub/week35/html/._week35-bs066.html +++ b/doc/pub/week35/html/._week35-bs066.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,67 +393,59 @@ MathJax.Hub.Config({

     

     

     

    -

    Deriving the Ridge Regression Equations

    +

    Ridge and LASSO Regression

    -

    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{\beta})=\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\right\}+\lambda\boldsymbol{\beta}^T\boldsymbol{\beta}, -$$ - -

    and -taking the derivatives with respect to \( \boldsymbol{\beta} \) 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 +

    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

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

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

    - +

    or we can state it as

    $$ -\sum_{i=0}^{p-1} \beta_i^2 \leq t, +{\displaystyle \min_{\boldsymbol{\beta}\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{\beta}\vert\vert_2^2, $$ -

    with \( t \) a finite positive number.

    - -

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

    +

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

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

    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{\beta}}_{\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{\beta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here. +

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

    -

    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 +$$ +{\displaystyle \min_{\boldsymbol{\beta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\beta}\vert\vert_2^2 +$$ + +

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

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

    For Ridge regression this becomes

    $$ -\tilde{\boldsymbol{y}}_{\mathrm{Ridge}}=\boldsymbol{X}\boldsymbol{\beta}_{\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}, +C(\boldsymbol{X},\boldsymbol{\beta})=\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\beta}\vert\vert_1, +$$ + +

    we have a new optimization equation

    +$$ +{\displaystyle \min_{\boldsymbol{\beta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\vert\vert_2^2+\lambda\vert\vert \boldsymbol{\beta}\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. $$ -

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

    @@ -472,6 +466,7 @@ $$

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs067.html b/doc/pub/week35/html/._week35-bs067.html index b4eabf91f..bb6fa5a3f 100644 --- a/doc/pub/week35/html/._week35-bs067.html +++ b/doc/pub/week35/html/._week35-bs067.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,22 +393,67 @@ MathJax.Hub.Config({

     

     

     

    -

    Interpreting the Ridge results

    +

    Deriving the Ridge Regression Equations

    -

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

    +

    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

    $$ -\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1. +C(\boldsymbol{X},\boldsymbol{\beta})=\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\right\}+\lambda\boldsymbol{\beta}^T\boldsymbol{\beta}, $$ -

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

    and +taking the derivatives with respect to \( \boldsymbol{\beta} \) 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{\beta}}_{\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} \beta_i^2 \leq t, +$$ + +

    with \( t \) a finite positive number.

    + +

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

    +$$ +\hat{\boldsymbol{\beta}}_{\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{\beta}}_{\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{\beta} \). These topics and other related ones, will be discussed after the more linear algebra oriented analysis here.

    -

    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.

    +

    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{\beta} =\boldsymbol{U}\boldsymbol{U}^T\boldsymbol{y}. +$$ + +

    For Ridge regression this becomes

    + +$$ +\tilde{\boldsymbol{y}}_{\mathrm{Ridge}}=\boldsymbol{X}\boldsymbol{\beta}_{\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} \).

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

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs068.html b/doc/pub/week35/html/._week35-bs068.html index 1f23c58c3..06fc6d904 100644 --- a/doc/pub/week35/html/._week35-bs068.html +++ b/doc/pub/week35/html/._week35-bs068.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,35 +393,22 @@ MathJax.Hub.Config({

     

     

     

    -

    More interpretations

    +

    Interpreting the Ridge results

    -

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

    +

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

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

    In this case the standard OLS results in

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

    and

    - -$$ -\boldsymbol{\beta}^{\mathrm{Ridge}} = \left(\boldsymbol{I}+\lambda\boldsymbol{I}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}=\left(1+\lambda\right)^{-1}\boldsymbol{\beta}^{\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. +

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

    -

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

    +

    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.

    @@ -438,6 +427,7 @@ Similarly, Mehta et al

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs069.html b/doc/pub/week35/html/._week35-bs069.html index 3e27a9cae..921a38051 100644 --- a/doc/pub/week35/html/._week35-bs069.html +++ b/doc/pub/week35/html/._week35-bs069.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,31 +393,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Deriving the Lasso Regression Equations

    +

    More interpretations

    -

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

    +

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

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

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

    +

    In this case the standard OLS results in

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

    we have that the derivative of the cost function is

    +

    and

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

    and reordering we have

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

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

    -

    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 this later.

    +

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

    @@ -433,6 +439,7 @@ $$

  • 69
  • 70
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/._week35-bs070.html b/doc/pub/week35/html/._week35-bs070.html index 8d5a73633..a456d380d 100644 --- a/doc/pub/week35/html/._week35-bs070.html +++ b/doc/pub/week35/html/._week35-bs070.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -391,610 +393,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Exercises for week 35

    +

    Deriving the Lasso Regression Equations

    -

    The exercises here are meant to prepare you for work with project 1. The first exercise is a follow-up of exercise 2 from week 35 August 30-September 3).

    - - -

    Exercise 1: Setting up various Python environments

    - -

    The first exercise here is of a mere technical art. We want you to have

    -
      -
    • git as a version control software and to establish a user account on a provider like GitHub. Other providers like GitLab etc are equally fine. You can also use the University of Oslo GitHub facilities.
    • -
    • Install various Python packages
    • -
    -

    We will make extensive use of Python as programming language and its -myriad of available libraries. You will find -IPython/Jupyter notebooks invaluable in your work. You can run R -codes in the Jupyter/IPython notebooks, with the immediate benefit of -visualizing your data. You can also use compiled languages like C++, -Rust, Fortran etc if you prefer. The focus in these lectures will be -on Python. -

    - -

    If you have Python installed (we recommend Python3) and you feel -pretty familiar with installing different packages, we recommend that -you install the following Python packages via pip as -

    - -
      -
    1. pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
    2. -
    -

    For Tensorflow, we recommend following the instructions in the text of -Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly -

    - -

    We will come back to tensorflow later.

    - -

    For Python3, replace pip with pip3.

    - -

    For OSX users we recommend, after having installed Xcode, to -install brew. Brew allows for a seamless installation of additional -software via for example -

    - -
      -
    1. brew install python3
    2. -
    -

    For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, -you can use pip as well and simply install Python as -

    - -
      -
    1. sudo apt-get install python3 (or python for Python2.7)
    2. -
    -

    If you don't want to perform these operations separately and venture -into the hassle of exploring how to set up dependencies and paths, we -recommend two widely used distrubutions which set up all relevant -dependencies for Python, namely -

    - - -

    which is an open source -distribution of the Python and R programming languages for large-scale -data processing, predictive analytics, and scientific computing, that -aims to simplify package management and deployment. Package versions -are managed by the package management system conda. -

    - - -

    is a Python -distribution for scientific and analytic computing distribution and -analysis environment, available for free and under a commercial -license. -

    - -

    We recommend using Anaconda if you are not too familiar with setting paths in a terminal environment.

    - - - - -

    Exercise 2: making your own data and exploring scikit-learn

    - -

    We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) and defined by random numbers computed with the uniform distribution. The function \( y \) is a quadratic polynomial in \( x \) with added stochastic noise according to the normal distribution \( \cal {N}(0,1) \). -The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points). -

    - - -
    -
    -
    -
    -
    -
    x = np.random.rand(100,1)
    -y = 2.0+5*x*x+0.1*np.random.randn(100,1)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - -
      -
    1. Write your own code (following the examples under the regression notes) for computing the parametrization of the data set fitting a second-order polynomial.
    2. -
    3. Use thereafter scikit-learn (see again the examples in the regression slides) and compare with your own code. When compairing with _scikit_learn_, make sure you set the option for the intercept to FALSE, see https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html. This feature will be explained in more detail during the lectures of week 35 and week 36. You can find more in https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/chapter3.html#more-on-rescaling-data.
    4. -
    5. Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as
    6. -
    -$$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} -\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, -$$ - -

    and the \( R^2 \) score function. -If \( \tilde{\boldsymbol{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as -

    -$$ -R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, -$$ - -

    where we have defined the mean value of \( \boldsymbol{y} \) as

    -$$ -\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. -$$ - -

    You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. -Discuss the meaning of these results. Try also to vary the coefficient in front of the added stochastic noise term and discuss the quality of the fits. -

    - - - -

    -

    -

    - -

    -Solution. -

    -
    -
    -

    - -

    The code here is an example of where we define our own design matrix and fit parameters \( \beta \).

    - - -
    -
    -
    -
    -
    -
    import os
    -import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -
    -def save_fig(fig_id):
    -    plt.savefig(image_path(fig_id) + ".png", format='png')
    -
    -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 given polynomial
    -X = np.zeros((len(x),3))
    -X[:,0] = 1.0
    -X[:,1] = x
    -X[:,2] = x**2
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -# matrix inversion to find beta
    -beta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    -print(beta)
    -# and then make the prediction
    -ytilde = X_train @ beta
    -print("Training R2")
    -print(R2(y_train,ytilde))
    -print("Training MSE")
    -print(MSE(y_train,ytilde))
    -ypredict = X_test @ beta
    -print("Test R2")
    -print(R2(y_test,ypredict))
    -print("Test MSE")
    -print(MSE(y_test,ypredict))
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - -

    -
    -

    - - - - - - -

    Exercise 3: Normalizing our data

    - -

    A much used approach before starting to train the data is to preprocess 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 -

    - -

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

    - -

    It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest -for testing. This can be done as follows with our design matrix \( \boldsymbol{X} \) and data \( \boldsymbol{y} \) (remember to import scikit-learn) -

    - - -
    -
    -
    -
    -
    -
    # split in training and test data
    -X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Then we can use the standard scaler to scale our data as

    - - -
    -
    -
    -
    -
    -
    scaler = StandardScaler()
    -scaler.fit(X_train)
    -X_train_scaled = scaler.transform(X_train)
    -X_test_scaled = scaler.transform(X_test)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    In this exercise we want you to to compute the MSE for the training -data and the test data as function of the complexity of a polynomial, -that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. -

    - -

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

    - -

    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.

    - - -

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

    - - - - -

    -b) -Perform an ordinary least squares and compute the means squared error and the \( R2 \) factor for the training data and the test data, with and without scaling. -

    - - - - -

    -c) -Add now a model which allows you to make polynomials up to degree \( 15 \). Perform a standard OLS fitting of the training data and compute the MSE and \( R2 \) for the training and test data and plot both test and training data MSE and \( R2 \) as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)? -

    - - - - - - -

    Exercise 4: Adding Ridge Regression

    - -

    This exercise is a continuation of exercise 2. We will use the same function to -generate our data set, still staying with a simple function \( y(x) \) -which we want to fit using linear regression, but now extending the -analysis to include the Ridge regression method. -

    - -

    We will thus again generate our own dataset for a function \( y(x) \) where -\( x \in [0,1] \) and defined by random numbers computed with the uniform -distribution. The function \( y \) is a quadratic polynomial in \( x \) with -added stochastic noise according to the normal distribution \( \cal{N}(0,1) \). -

    - -

    The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points).

    - - -
    -
    -
    -
    -
    -
    x = np.random.rand(100)
    -y = 2.0+5*x*x+0.1*np.random.randn(100)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Write your own code for the Ridge method (see chapter 3.4 of Hastie et al., equations (3.43) and (3.44)) and compute the parametrization for different values of \( \lambda \). Compare and analyze your results with those from exercise 3. Study the dependence on \( \lambda \) while also varying the strength of the noise in your expression for \( y(x) \).

    - -

    The code here allows you to perform your own Ridge calculation and -perform calculations for various values of the regularization -parameter \( \lambda \). This program can easily be extended upon. -

    - - - -
    -
    -
    -
    -
    -
    import os
    -import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn.preprocessing import StandardScaler
    -
    -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
    -
    -
    -# A seed just to ensure that the random numbers are the same for every run.
    -# Useful for eventual debugging.
    -np.random.seed(3155)
    -
    -x = np.random.rand(100)
    -y = 2.0+5*x*x+0.1*np.random.randn(100)
    -
    -# number of features p (here degree of polynomial
    -p = 3
    -#  The design matrix now as function of a given polynomial
    -X = np.zeros((len(x),p))
    -X[:,0] = 1.0
    -X[:,1] = x
    -X[:,2] = x*x
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# matrix inversion to find beta
    -OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    -print(OLSbeta)
    -# and then make the prediction
    -ytildeOLS = X_train @ OLSbeta
    -print("Training R2 for OLS")
    -print(R2(y_train,ytildeOLS))
    -print("Training MSE for OLS")
    -print(MSE(y_train,ytildeOLS))
    -ypredictOLS = X_test @ OLSbeta
    -print("Test R2 for OLS")
    -print(R2(y_test,ypredictOLS))
    -print("Test MSE OLS")
    -print(MSE(y_test,ypredictOLS))
    -
    -# Repeat now for Ridge regression and various values of the regularization parameter
    -I = np.eye(p,p)
    -# Decide which values of lambda to use
    -nlambdas = 20
    -MSEPredict = np.zeros(nlambdas)
    -MSETrain = np.zeros(nlambdas)
    -lambdas = np.logspace(-4, 1, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    Ridgebeta = np.linalg.inv(X_train.T @ X_train+lmb*I) @ X_train.T @ y_train
    -    # and then make the prediction
    -    ytildeRidge = X_train @ Ridgebeta
    -    ypredictRidge = X_test @ Ridgebeta
    -    MSEPredict[i] = MSE(y_test,ypredictRidge)
    -    MSETrain[i] = MSE(y_train,ytildeRidge)
    -# Now plot the results
    -plt.figure()
    -plt.plot(np.log10(lambdas), MSETrain, label = 'MSE Ridge train')
    -plt.plot(np.log10(lambdas), MSEPredict, 'r--', label = 'MSE Ridge Test')
    -plt.xlabel('log10(lambda)')
    -plt.ylabel('MSE')
    -plt.legend()
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Repeat the above but using the functionality of -Scikit-Learn. Compare your code with the results from -Scikit-Learn. Remember to run with the same random numbers for -generating \( x \) and \( y \). Observe also that when you compare with Scikit-Learn, you need to pay attention to how the intercept is dealt with. -

    - -

    Finally, using Scikit-Learn or your own code, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as

    -$$ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} -\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, -$$ - -

    and the \( R^2 \) score function. -If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as -

    -$$ -R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, -$$ - -

    where we have defined the mean value of \( \hat{y} \) as

    -$$ -\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. -$$ - -

    Discuss these quantities as functions of the variable \( \lambda \) in Ridge regression.

    - - - - -

    Exercise 5: Analytical exercises

    - -

    In this exercise we derive the expressions for various derivatives of -products of vectors and matrices. Such derivatives are central to the -optimization of various cost functions. Although we will often use -automatic differentiation in actual calculations, to be able to have -analytical expressions is extremely helpful in case we have simpler -derivatives as well as when we analyze various properties (like second -derivatives) of the chosen cost functions. Vectors are always written -as boldfaced lower case letters and matrices as upper case boldfaced -letters. -

    - -

    Show that

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

    and

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

    and

    -$$ -\frac{\partial \left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)^T\left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)}{\partial \boldsymbol{s}} = -2\left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)^T\boldsymbol{A}, -$$ - -

    and finally find the second derivative of this function with respect to the vector \( \boldsymbol{s} \).

    - -

    Hint: In these exercises it is always useful to write out with summation indices the various quantities. -As an example, consider the function -

    +

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

    $$ -f(\boldsymbol{x}) =\boldsymbol{A}\boldsymbol{x}, +C(\boldsymbol{X},\boldsymbol{\beta})=\left\{(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})\right\}+\lambda\vert\vert\boldsymbol{\beta}\vert\vert_1, $$ -

    which reads for a specific component \( f_i \) (we define the matrix \( \boldsymbol{A} \) to have dimension \( n\times n \) and the vector $\boldsymbol{x} to have length \( n \))

    - +

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

    $$ -f_i =\sum_{j=0}^{n-1}a_{ij}x_j, +\frac{d \vert \beta\vert}{d \boldsymbol{\beta}}=\mathrm{sgn}(\boldsymbol{\beta})=\left\{\begin{array}{cc} 1 & \beta > 0 \\-1 & \beta < 0, \end{array}\right. $$ -

    which leads to

    +

    we have that the derivative of the cost function is

    + $$ -\frac{\partial f_i}{\partial x_j}= a_{ij}, +\frac{\partial C(\boldsymbol{X},\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}=-2\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta})+\lambda sgn(\boldsymbol{\beta})=0, $$ -

    and written out in terms of the vector \( \boldsymbol{x} \) we have

    +

    and reordering we have

    $$ -\frac{\partial f(\boldsymbol{x})}{\partial \boldsymbol{x}}= \boldsymbol{A}. +\boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta}+\lambda sgn(\boldsymbol{\beta})=2\boldsymbol{X}^T\boldsymbol{y}. $$ +

    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 this later.

    -

    diff --git a/doc/pub/week35/html/._week35-bs071.html b/doc/pub/week35/html/._week35-bs071.html index e2c2b2680..e4b010848 100644 --- a/doc/pub/week35/html/._week35-bs071.html +++ b/doc/pub/week35/html/._week35-bs071.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression - + - - - @@ -285,8 +290,6 @@ MathJax.Hub.Config({ - -
    -
    -

     

     

     

    - +

    Exercises for week 35

    -

    Exercises for week 36, September 6-10

    +

    The exercises here are meant to prepare you for work with project 1. The first exercise is a follow-up of exercise 2 from week 35 August 30-September 3).

    -

    -The exercises here are meant to prepare you for work with project 1. The first exercise is a follow-up of exercise 2 from week 35 August 30-September 3). - -

    +

    Exercise 1: Setting up various Python environments

    -

    Exercise 1: Adding Ridge and Lasso Regression

    +

    The first exercise here is of a mere technical art. We want you to have

    +
      +
    • git as a version control software and to establish a user account on a provider like GitHub. Other providers like GitLab etc are equally fine. You can also use the University of Oslo GitHub facilities.
    • +
    • Install various Python packages
    • +
    +

    We will make extensive use of Python as programming language and its +myriad of available libraries. You will find +IPython/Jupyter notebooks invaluable in your work. You can run R +codes in the Jupyter/IPython notebooks, with the immediate benefit of +visualizing your data. You can also use compiled languages like C++, +Rust, Fortran etc if you prefer. The focus in these lectures will be +on Python. +

    + +

    If you have Python installed (we recommend Python3) and you feel +pretty familiar with installing different packages, we recommend that +you install the following Python packages via pip as +

    + +
      +
    1. pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
    2. +
    +

    For Tensorflow, we recommend following the instructions in the text of +Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly +

    + +

    We will come back to tensorflow later.

    + +

    For Python3, replace pip with pip3.

    + +

    For OSX users we recommend, after having installed Xcode, to +install brew. Brew allows for a seamless installation of additional +software via for example +

    + +
      +
    1. brew install python3
    2. +
    +

    For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +you can use pip as well and simply install Python as +

    + +
      +
    1. sudo apt-get install python3 (or python for Python2.7)
    2. +
    +

    If you don't want to perform these operations separately and venture +into the hassle of exploring how to set up dependencies and paths, we +recommend two widely used distrubutions which set up all relevant +dependencies for Python, namely +

    + + +

    which is an open source +distribution of the Python and R programming languages for large-scale +data processing, predictive analytics, and scientific computing, that +aims to simplify package management and deployment. Package versions +are managed by the package management system conda. +

    + + +

    is a Python +distribution for scientific and analytic computing distribution and +analysis environment, available for free and under a commercial +license. +

    + +

    We recommend using Anaconda if you are not too familiar with setting paths in a terminal environment.

    + + + + +

    Exercise 2: making your own data and exploring scikit-learn

    + +

    We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) and defined by random numbers computed with the uniform distribution. The function \( y \) is a quadratic polynomial in \( x \) with added stochastic noise according to the normal distribution \( \cal {N}(0,1) \). +The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points). +

    + + +
    +
    +
    +
    +
    +
    x = np.random.rand(100,1)
    +y = 2.0+5*x*x+0.1*np.random.randn(100,1)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +
      +
    1. Write your own code (following the examples under the regression notes) for computing the parametrization of the data set fitting a second-order polynomial.
    2. +
    3. Use thereafter scikit-learn (see again the examples in the regression slides) and compare with your own code. When compairing with _scikit_learn_, make sure you set the option for the intercept to FALSE, see https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html. This feature will be explained in more detail during the lectures of week 35 and week 36. You can find more in https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/chapter3.html#more-on-rescaling-data.
    4. +
    5. Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as
    6. +
    +$$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} +\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, +$$ + +

    and the \( R^2 \) score function. +If \( \tilde{\boldsymbol{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +

    +$$ +R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +$$ + +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    +$$ +\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. +$$ + +

    You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. +Discuss the meaning of these results. Try also to vary the coefficient in front of the added stochastic noise term and discuss the quality of the fits. +

    + +

    -This exercise is a continuation of exercise 2 from exercise set 1 -(week 35, August 30-September 3). We will use the same function to +

    +

    + +

    +Solution. +

    +
    +
    +

    + +

    The code here is an example of where we define our own design matrix and fit parameters \( \beta \).

    + + +
    +
    +
    +
    +
    +
    import os
    +import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +
    +def save_fig(fig_id):
    +    plt.savefig(image_path(fig_id) + ".png", format='png')
    +
    +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 given polynomial
    +X = np.zeros((len(x),3))
    +X[:,0] = 1.0
    +X[:,1] = x
    +X[:,2] = x**2
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +# matrix inversion to find beta
    +beta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    +print(beta)
    +# and then make the prediction
    +ytilde = X_train @ beta
    +print("Training R2")
    +print(R2(y_train,ytilde))
    +print("Training MSE")
    +print(MSE(y_train,ytilde))
    +ypredict = X_test @ beta
    +print("Test R2")
    +print(R2(y_test,ypredict))
    +print("Test MSE")
    +print(MSE(y_test,ypredict))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +

    +
    +

    + + + + + + +

    Exercise 3: Normalizing our data

    + +

    A much used approach before starting to train the data is to preprocess 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 +

    + +

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

    + +

    It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest +for testing. This can be done as follows with our design matrix \( \boldsymbol{X} \) and data \( \boldsymbol{y} \) (remember to import scikit-learn) +

    + + +
    +
    +
    +
    +
    +
    # split in training and test data
    +X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Then we can use the standard scaler to scale our data as

    + + +
    +
    +
    +
    +
    +
    scaler = StandardScaler()
    +scaler.fit(X_train)
    +X_train_scaled = scaler.transform(X_train)
    +X_test_scaled = scaler.transform(X_test)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    In this exercise we want you to to compute the MSE for the training +data and the test data as function of the complexity of a polynomial, +that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +

    + +

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

    + +

    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.

    + + +

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

    + + + + +

    +b) +Perform an ordinary least squares and compute the means squared error and the \( R2 \) factor for the training data and the test data, with and without scaling. +

    + + + + +

    +c) +Add now a model which allows you to make polynomials up to degree \( 15 \). Perform a standard OLS fitting of the training data and compute the MSE and \( R2 \) for the training and test data and plot both test and training data MSE and \( R2 \) as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)? +

    + + + + + + +

    Exercise 4: Adding Ridge Regression

    + +

    This exercise is a continuation of exercise 2. We will use the same function to generate our data set, still staying with a simple function \( y(x) \) which we want to fit using linear regression, but now extending the -analysis to include the Ridge and the Lasso regression methods. +analysis to include the Ridge regression method. +

    -

    -We will thus again generate our own dataset for a function \( y(x) \) where +

    We will thus again generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) and defined by random numbers computed with the uniform distribution. The function \( y \) is a quadratic polynomial in \( x \) with added stochastic noise according to the normal distribution \( \cal{N}(0,1) \). +

    -

    -The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points). -

    +

    The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points).

    -
    x = np.random.rand(100)
    +
    +
    +
    +
    +
    +
    x = np.random.rand(100)
     y = 2.0+5*x*x+0.1*np.random.randn(100)
    -
    -

    -Write your own code for the Ridge method (see chapter 3.4 of Hastie et al., equations (3.43) and (3.44)) and compute the parametrization for different values of \( \lambda \). Compare and analyze your results with those from exercise 3. Study the dependence on \( \lambda \) while also varying the strength of the noise in your expression for \( y(x) \). +

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    -The code here allows you to perform your own Ridge calculation and +

    Write your own code for the Ridge method (see chapter 3.4 of Hastie et al., equations (3.43) and (3.44)) and compute the parametrization for different values of \( \lambda \). Compare and analyze your results with those from exercise 3. Study the dependence on \( \lambda \) while also varying the strength of the noise in your expression for \( y(x) \).

    + +

    The code here allows you to perform your own Ridge calculation and perform calculations for various values of the regularization parameter \( \lambda \). This program can easily be extended upon. +

    -

    -

    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -463,10 +859,6 @@ X[:,1] =
     X[:,2] = x*x
     # 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)
    -scaler = StandardScaler()
    -scaler.fit(X_train)
    -X_train_scaled = scaler.transform(X_train)
    -X_test_scaled = scaler.transform(X_test)
     
     # matrix inversion to find beta
     OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
    @@ -506,204 +898,105 @@ plt.xlabel('
     plt.ylabel('MSE')
     plt.legend()
     plt.show()
    -
    -

    -Repeat the above but using the functionality of +

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

    Repeat the above but using the functionality of Scikit-Learn. Compare your code with the results from Scikit-Learn. Remember to run with the same random numbers for generating \( x \) and \( y \). Observe also that when you compare with Scikit-Learn, you need to pay attention to how the intercept is dealt with. +

    -

    -Finally, using Scikit-Learn or your own code, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as +

    Finally, using Scikit-Learn or your own code, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as

    $$ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -and the \( R^2 \) score function. +

    and the \( R^2 \) score function. If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +

    $$ R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \hat{y} \) as +

    where we have defined the mean value of \( \hat{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -Discuss these quantities as functions of the variable \( \lambda \) in the Ridge and Lasso regression methods. +

    Discuss these quantities as functions of the variable \( \lambda \) in Ridge regression.

    -

    Exercise: Linear Regression for a two-dimensional function

    - -

    -This is a longer exercise and the aim is to study in more detail various -regression methods, including the Ordinary Least Squares (OLS) method, -Ridge regression and finally Lasso regression. -This exercise forms a part of project 1. - -

    -We will study how to fit polynomials to a specific -two-dimensional function called Franke's -function. This -is a function which has been widely used when testing various -interpolation and fitting algorithms. - -

    -The Franke function, which is a weighted sum of four exponentials reads as follows -$$ -\begin{align*} -f(x,y) &= \frac{3}{4}\exp{\left(-\frac{(9x-2)^2}{4} - \frac{(9y-2)^2}{4}\right)}+\frac{3}{4}\exp{\left(-\frac{(9x+1)^2}{49}- \frac{(9y+1)}{10}\right)} \\ -&+\frac{1}{2}\exp{\left(-\frac{(9x-7)^2}{4} - \frac{(9y-3)^2}{4}\right)} -\frac{1}{5}\exp{\left(-(9x-4)^2 - (9y-7)^2\right) }. -\end{align*} -$$ - -

    -The function will be defined for \( x,y\in [0,1] \). Our first step will -be to perform an OLS regression analysis of this function, trying out -a polynomial fit with an \( x \) and \( y \) dependence of the form \( [x, y, -x^2, y^2, xy, \dots] \). We will fit a -function (for example a polynomial) of \( x \) and \( y \). Thereafter we -will repeat much of the same procedure using the Ridge and Lasso -regression methods, introducing thus a dependence on the bias -(penalty) \( \lambda \). - -

    -The Python fucntion for the Franke function is included here (it performs also a three-dimensional plot of it) -

    - - -

    from mpl_toolkits.mplot3d import Axes3D
    -import matplotlib.pyplot as plt
    -from matplotlib import cm
    -from matplotlib.ticker import LinearLocator, FormatStrFormatter
    -import numpy as np
    -from random import random, seed
    -
    -fig = plt.figure()
    -ax = fig.gca(projection='3d')
    -
    -# Make data.
    -x = np.arange(0, 1, 0.05)
    -y = np.arange(0, 1, 0.05)
    -x, y = np.meshgrid(x,y)
    -
    -
    -def FrankeFunction(x,y):
    -    term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
    -    term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
    -    term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
    -    term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
    -    return term1 + term2 + term3 + term4
    -
    -
    -z = FrankeFunction(x, y)
    -
    -# Plot the surface.
    -surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
    -                       linewidth=0, antialiased=False)
    -
    -# Customize the z axis.
    -ax.set_zlim(-0.10, 1.40)
    -ax.zaxis.set_major_locator(LinearLocator(10))
    -ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
    -
    -# Add a color bar which maps values to colors.
    -fig.colorbar(surf, shrink=0.5, aspect=5)
    -
    -plt.show()
    -
    -

    -We will generate our own dataset for a function -\( \mathrm{FrankeFunction}(x,y) \) with \( x,y \in [0,1] \). The function -\( f(x,y) \) is the Franke function. You should explore also the addition -an added stochastic noise to this function using the normal -distribution \( \cal{N}(0,1) \). - -

    -Write your own code (using either a matrix inversion or a singular -value decomposition from e.g., numpy ) or use your code and perform a standard least square regression -analysis using polynomials in \( x \) and \( y \) up to fifth order. You can use scikit-learn as well. - -

    -Evaluate the Mean Squared error (MSE) - -$$ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} -\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, -$$ - -

    -and the \( R^2 \) score function. If \( \tilde{\hat{y}}_i \) is the predicted -value of the \( i-th \) sample and \( y_i \) is the corresponding true value, -then the score \( R^2 \) is defined as - -$$ -R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, -$$ - -

    -where we have defined the mean value of \( \hat{y} \) as - -$$ -\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. -$$ - -

    -You should split your data in train and test and also consider scaling the data. - -

    -To set up the design matrix, the following code can be used -

    - - -

    def FrankeFunction(x,y):
    -	term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
    -	term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
    -	term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
    -	term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
    -	return term1 + term2 + term3 + term4
    -
    -
    -def create_X(x, y, n ):
    -	if len(x.shape) > 1:
    -		x = np.ravel(x)
    -		y = np.ravel(y)
    -
    -	N = len(x)
    -	l = int((n+1)*(n+2)/2)		# Number of elements in beta
    -	X = np.ones((N,l))
    -
    -	for i in range(1,n+1):
    -		q = int((i)*(i+1)/2)
    -		for k in range(i+1):
    -			X[:,q+k] = (x**(i-k))*(y**k)
    -
    -	return X
    -
    -
    -# Making meshgrid of datapoints and compute Franke's function
    -n = 5
    -N = 1000
    -x = np.sort(np.random.uniform(0, 1, N))
    -y = np.sort(np.random.uniform(0, 1, N))
    -z = FrankeFunction(x, y)
    -X = create_X(x, y, n=n)    
    -
    -

    -Write then your own code for the Ridge method or use Scikit-Learn. -Perform the same analysis as you did for ordinary Least Squares (for the same polynomials) but now for different values of \( \lambda \). Compare and -analyze your results with those obtained with ordinary Least Squares. Study the -dependence on \( \lambda \). - -

    -This part is essentially a repeat of the previous ones, but now -with Lasso regression. Write either your own code or -use the functionalities of Scikit-Learn (recommended). -Give a -critical discussion of the three methods and a judgement of which -model fits the data best. - -

    + +

    Exercise 5: Analytical exercises

    + +

    In this exercise we derive the expressions for various derivatives of +products of vectors and matrices. Such derivatives are central to the +optimization of various cost functions. Although we will often use +automatic differentiation in actual calculations, to be able to have +analytical expressions is extremely helpful in case we have simpler +derivatives as well as when we analyze various properties (like second +derivatives) of the chosen cost functions. Vectors are always written +as boldfaced lower case letters and matrices as upper case boldfaced +letters. +

    + +

    Show that

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

    and

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

    and

    +$$ +\frac{\partial \left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)^T\left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)}{\partial \boldsymbol{s}} = -2\left(\boldsymbol{x}-\boldsymbol{A}\boldsymbol{s}\right)^T\boldsymbol{A}, +$$ + +

    and finally find the second derivative of this function with respect to the vector \( \boldsymbol{s} \).

    + +

    Hint: In these exercises it is always useful to write out with summation indices the various quantities. +As an example, consider the function +

    + +$$ +f(\boldsymbol{x}) =\boldsymbol{A}\boldsymbol{x}, +$$ + +

    which reads for a specific component \( f_i \) (we define the matrix \( \boldsymbol{A} \) to have dimension \( n\times n \) and the vector $\boldsymbol{x} to have length \( n \))

    + +$$ +f_i =\sum_{j=0}^{n-1}a_{ij}x_j, +$$ + +

    which leads to

    +$$ +\frac{\partial f_i}{\partial x_j}= a_{ij}, +$$ + +

    and written out in terms of the vector \( \boldsymbol{x} \) we have

    +$$ +\frac{\partial f(\boldsymbol{x})}{\partial \boldsymbol{x}}= \boldsymbol{A}. +$$ + + +

      @@ -721,25 +1014,18 @@ model fits the data best.
    • 72
    -
    - - -
    - - - diff --git a/doc/pub/week35/html/week35-bs.html b/doc/pub/week35/html/week35-bs.html index 3a6fa9a41..103514007 100644 --- a/doc/pub/week35/html/week35-bs.html +++ b/doc/pub/week35/html/week35-bs.html @@ -96,6 +96,7 @@ doconce format html week35.do.txt --html_style=bootstrap --pygments_html_style=d 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -309,7 +310,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -318,68 +319,69 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Examples relevant for the exercises
  • Optimizing our parameters, more details
  • -
  • 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
  • -
  • Meet the Hessian Matrix
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • 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
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Material for lecture Thursday, August 31
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • 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
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with the SVD
  • -
  • What does it mean?
  • -
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • -
  • Ridge and LASSO Regression
  • -
  • Deriving the Ridge Regression Equations
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • Deriving the Lasso Regression Equations
  • -
  • Exercises for week 35
  • -
  • Exercise 1: Setting up various Python environments
  • -
  • Exercise 2: making your own data and exploring scikit-learn
  • -
  • Exercise 3: Normalizing our data
  • -
  • Exercise 4: Adding Ridge Regression
  • -
  • Exercise 5: Analytical exercises
  • +
  • Example 2
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • 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
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Material for lecture Thursday, August 31
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • 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
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with the SVD
  • +
  • What does it mean?
  • +
  • And finally \( \boldsymbol{X}\boldsymbol{X}^T \)
  • +
  • Ridge and LASSO Regression
  • +
  • Deriving the Ridge Regression Equations
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • Deriving the Lasso Regression Equations
  • +
  • Exercises for week 35
  • +
  • Exercise 1: Setting up various Python environments
  • +
  • Exercise 2: making your own data and exploring scikit-learn
  • +
  • Exercise 3: Normalizing our data
  • +
  • Exercise 4: Adding Ridge Regression
  • +
  • Exercise 5: Analytical exercises
  • @@ -434,7 +436,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 71
  • +
  • 72
  • »
  • diff --git a/doc/pub/week35/html/week35-reveal.html b/doc/pub/week35/html/week35-reveal.html index 1da9a75fa..6050668ba 100644 --- a/doc/pub/week35/html/week35-reveal.html +++ b/doc/pub/week35/html/week35-reveal.html @@ -806,6 +806,12 @@ Jacobian is only a single-column vector, or an \( m\times 1 \) matrix. If on the other hand \( \boldsymbol{y} \) is a scalar, the Jacobian becomes a \( 1\times n \) matrix.

    + +

    When this matrix is a square matrix \( m=n \), its determinant is often referred to as the Jacobian +determinant. Both the matrix and (if \( m=n \)) the determinant are +often referred to simply as the Jacobian. The Jacobian matrix represents the differential of \( \boldsymbol{y} \) at every point where the +vector is differentiable. +

    @@ -835,30 +841,65 @@ $$ \frac{\partial \boldsymbol{y} }{\partial \boldsymbol{x}}= \boldsymbol{A}. $$

     
    +

    +
    +

    Example 2

    + +

    We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications

    + +$$ +\alpha = \boldsymbol{y}^T\boldsymbol{A}\boldsymbol{x}$,

     
    $$ + +

    with \( \boldsymbol{y} \) a vector of length \( m \), \( \boldsymbol{A} \) an \( m\times n \) matrix and \( \boldsymbol{x} \) a vector of length \( n \). We assume also that \( \boldsymbol{A} \) does not depend on any of the two vectors. +In order to find the derivative of \( \alpha \) with respect to the two vectors, we define an intermediate vector \( \boldsymbol{z} \). We define first +\( \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A} \), a vector of length \( n \). We have then +

    +$$ +

     
    +\alpha = \boldsymbol{z}^T\boldsymbol{x}$, +

     
    +$$ + +

    which means that (using our previous example) we have

    +$$ +

     
    +\frac{\partial \alpha}{\partial \boldsymbol{x}} = \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A}. +

     
    +$$ + +

    Since \( \alpha \) is a scalar we have \( \alpha =\alpha^T=\boldsymbol{x}^T\boldsymbol{A}^T\boldsymbol{y} \). Defining now \( \boldsymbol{z}=\boldsymbol{x}^T\boldsymbol{A}^T \) we find that

    +$$ +

     
    +\frac{\partial \alpha}{\partial \boldsymbol{y}} = \boldsymbol{z}^T=\boldsymbol{x}^T\boldsymbol{A}^T.. +

     
    +$$ + + +$$ +

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

     
    +$$ -

     
    $$ +

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

     
    +$$ -

     
    $$ +

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

     

    See the jupyter-book (complete lecture notes) for the derivations of these relations.

    diff --git a/doc/pub/week35/html/week35-solarized.html b/doc/pub/week35/html/week35-solarized.html index ea38042b3..e3ca99cc1 100644 --- a/doc/pub/week35/html/week35-solarized.html +++ b/doc/pub/week35/html/week35-solarized.html @@ -123,6 +123,7 @@ div.toc p,a { 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -888,6 +889,12 @@ on the other hand \( \boldsymbol{y} \) is a scalar, the Jacobian becomes a \( 1\times n \) matrix.

    +

    When this matrix is a square matrix \( m=n \), its determinant is often referred to as the Jacobian +determinant. Both the matrix and (if \( m=n \)) the determinant are +often referred to simply as the Jacobian. The Jacobian matrix represents the differential of \( \boldsymbol{y} \) at every point where the +vector is differentiable. +

    +









    Derivatives, example 1

    @@ -911,6 +918,34 @@ $$ $$ +









    +

    Example 2

    + +

    We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications

    + +$$ +\alpha = \boldsymbol{y}^T\boldsymbol{A}\boldsymbol{x}$, +$$ + +

    with \( \boldsymbol{y} \) a vector of length \( m \), \( \boldsymbol{A} \) an \( m\times n \) matrix and \( \boldsymbol{x} \) a vector of length \( n \). We assume also that \( \boldsymbol{A} \) does not depend on any of the two vectors. +In order to find the derivative of \( \alpha \) with respect to the two vectors, we define an intermediate vector \( \boldsymbol{z} \). We define first +\( \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A} \), a vector of length \( n \). We have then +

    +$$ +\alpha = \boldsymbol{z}^T\boldsymbol{x}$, +$$ + +

    which means that (using our previous example) we have

    +$$ +\frac{\partial \alpha}{\partial \boldsymbol{x}} = \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A}. +$$ + +

    Since \( \alpha \) is a scalar we have \( \alpha =\alpha^T=\boldsymbol{x}^T\boldsymbol{A}^T\boldsymbol{y} \). Defining now \( \boldsymbol{z}=\boldsymbol{x}^T\boldsymbol{A}^T \) we find that

    +$$ +\frac{\partial \alpha}{\partial \boldsymbol{y}} = \boldsymbol{z}^T=\boldsymbol{x}^T\boldsymbol{A}^T.. +$$ + + $$ \frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, $$ diff --git a/doc/pub/week35/html/week35.html b/doc/pub/week35/html/week35.html index 4a8b811ab..0125443ab 100644 --- a/doc/pub/week35/html/week35.html +++ b/doc/pub/week35/html/week35.html @@ -200,6 +200,7 @@ div.toc p,a { 'some-useful-matrix-and-vector-expressions'), ('The Jacobian', 2, None, 'the-jacobian'), ('Derivatives, example 1', 2, None, 'derivatives-example-1'), + ('Example 2', 2, None, 'example-2'), ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, @@ -965,6 +966,12 @@ on the other hand \( \boldsymbol{y} \) is a scalar, the Jacobian becomes a \( 1\times n \) matrix.

    +

    When this matrix is a square matrix \( m=n \), its determinant is often referred to as the Jacobian +determinant. Both the matrix and (if \( m=n \)) the determinant are +often referred to simply as the Jacobian. The Jacobian matrix represents the differential of \( \boldsymbol{y} \) at every point where the +vector is differentiable. +

    +









    Derivatives, example 1

    @@ -988,6 +995,34 @@ $$ $$ +









    +

    Example 2

    + +

    We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications

    + +$$ +\alpha = \boldsymbol{y}^T\boldsymbol{A}\boldsymbol{x}$, +$$ + +

    with \( \boldsymbol{y} \) a vector of length \( m \), \( \boldsymbol{A} \) an \( m\times n \) matrix and \( \boldsymbol{x} \) a vector of length \( n \). We assume also that \( \boldsymbol{A} \) does not depend on any of the two vectors. +In order to find the derivative of \( \alpha \) with respect to the two vectors, we define an intermediate vector \( \boldsymbol{z} \). We define first +\( \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A} \), a vector of length \( n \). We have then +

    +$$ +\alpha = \boldsymbol{z}^T\boldsymbol{x}$, +$$ + +

    which means that (using our previous example) we have

    +$$ +\frac{\partial \alpha}{\partial \boldsymbol{x}} = \boldsymbol{z}^T=\boldsymbol{y}^T\boldsymbol{A}. +$$ + +

    Since \( \alpha \) is a scalar we have \( \alpha =\alpha^T=\boldsymbol{x}^T\boldsymbol{A}^T\boldsymbol{y} \). Defining now \( \boldsymbol{z}=\boldsymbol{x}^T\boldsymbol{A}^T \) we find that

    +$$ +\frac{\partial \alpha}{\partial \boldsymbol{y}} = \boldsymbol{z}^T=\boldsymbol{x}^T\boldsymbol{A}^T.. +$$ + + $$ \frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, $$ diff --git a/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz b/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz index 47ded15ac..ef9e0ee08 100644 Binary files a/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz and b/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz differ diff --git a/doc/pub/week35/ipynb/week35.ipynb b/doc/pub/week35/ipynb/week35.ipynb index 89291e827..8031adb43 100644 --- a/doc/pub/week35/ipynb/week35.ipynb +++ b/doc/pub/week35/ipynb/week35.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "272435cb", + "id": "c5b74a38", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "f093dc4f", + "id": "29510431", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "265f9aa7", + "id": "f4d4d962", "metadata": { "editable": true }, @@ -49,7 +49,7 @@ }, { "cell_type": "markdown", - "id": "462c23c5", + "id": "80396e96", "metadata": { "editable": true }, @@ -69,7 +69,7 @@ }, { "cell_type": "markdown", - "id": "9301fed2", + "id": "2345ae8b", "metadata": { "editable": true }, @@ -103,7 +103,7 @@ }, { "cell_type": "markdown", - "id": "a65340db", + "id": "f8c7dcd5", "metadata": { "editable": true }, @@ -125,7 +125,7 @@ }, { "cell_type": "markdown", - "id": "ac3e11cb", + "id": "ab8b9f75", "metadata": { "editable": true }, @@ -153,7 +153,7 @@ }, { "cell_type": "markdown", - "id": "573be022", + "id": "cc5516a9", "metadata": { "editable": true }, @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "8fd21bf4", + "id": "13465787", "metadata": { "editable": true }, @@ -180,7 +180,7 @@ }, { "cell_type": "markdown", - "id": "ffe94532", + "id": "513aed1f", "metadata": { "editable": true }, @@ -195,7 +195,7 @@ }, { "cell_type": "markdown", - "id": "bc9309fa", + "id": "0cd550bf", "metadata": { "editable": true }, @@ -208,7 +208,7 @@ }, { "cell_type": "markdown", - "id": "22893c01", + "id": "625ab412", "metadata": { "editable": true }, @@ -220,7 +220,7 @@ }, { "cell_type": "markdown", - "id": "8bfce1af", + "id": "4d15ed55", "metadata": { "editable": true }, @@ -230,7 +230,7 @@ }, { "cell_type": "markdown", - "id": "0745c236", + "id": "9700bc52", "metadata": { "editable": true }, @@ -241,7 +241,7 @@ }, { "cell_type": "markdown", - "id": "6d13835b", + "id": "7e670d68", "metadata": { "editable": true }, @@ -259,7 +259,7 @@ }, { "cell_type": "markdown", - "id": "495f813a", + "id": "50d97c76", "metadata": { "editable": true }, @@ -270,7 +270,7 @@ }, { "cell_type": "markdown", - "id": "dad327bb", + "id": "18270b13", "metadata": { "editable": true }, @@ -282,7 +282,7 @@ }, { "cell_type": "markdown", - "id": "79a03a3a", + "id": "b8f08b27", "metadata": { "editable": true }, @@ -292,7 +292,7 @@ }, { "cell_type": "markdown", - "id": "9649f653", + "id": "9ebb6dba", "metadata": { "editable": true }, @@ -304,7 +304,7 @@ }, { "cell_type": "markdown", - "id": "af19c028", + "id": "a40e9e13", "metadata": { "editable": true }, @@ -314,7 +314,7 @@ }, { "cell_type": "markdown", - "id": "93f05270", + "id": "6cf8984b", "metadata": { "editable": true }, @@ -326,7 +326,7 @@ }, { "cell_type": "markdown", - "id": "c8a3416f", + "id": "13b6e26a", "metadata": { "editable": true }, @@ -336,7 +336,7 @@ }, { "cell_type": "markdown", - "id": "9a82182d", + "id": "9bcac54e", "metadata": { "editable": true }, @@ -355,7 +355,7 @@ }, { "cell_type": "markdown", - "id": "816ca248", + "id": "5e354d85", "metadata": { "editable": true }, @@ -365,7 +365,7 @@ }, { "cell_type": "markdown", - "id": "215690d7", + "id": "a33079f8", "metadata": { "editable": true }, @@ -377,7 +377,7 @@ }, { "cell_type": "markdown", - "id": "4b2c135a", + "id": "41edee75", "metadata": { "editable": true }, @@ -387,7 +387,7 @@ }, { "cell_type": "markdown", - "id": "18509d96", + "id": "dd182674", "metadata": { "editable": true }, @@ -403,7 +403,7 @@ }, { "cell_type": "markdown", - "id": "6f5f06fb", + "id": "1a39a0a9", "metadata": { "editable": true }, @@ -423,7 +423,7 @@ }, { "cell_type": "markdown", - "id": "23031b67", + "id": "11e0d7e0", "metadata": { "editable": true }, @@ -433,7 +433,7 @@ }, { "cell_type": "markdown", - "id": "2e4d63d0", + "id": "945cb6ec", "metadata": { "editable": true }, @@ -444,7 +444,7 @@ }, { "cell_type": "markdown", - "id": "7f9c0240", + "id": "d84e59f1", "metadata": { "editable": true }, @@ -463,7 +463,7 @@ }, { "cell_type": "markdown", - "id": "c784ade5", + "id": "8d94bcee", "metadata": { "editable": true }, @@ -473,7 +473,7 @@ }, { "cell_type": "markdown", - "id": "c82604ad", + "id": "021b178b", "metadata": { "editable": true }, @@ -485,7 +485,7 @@ }, { "cell_type": "markdown", - "id": "c2a79c18", + "id": "e8f26659", "metadata": { "editable": true }, @@ -495,7 +495,7 @@ }, { "cell_type": "markdown", - "id": "ce13e7da", + "id": "943789b0", "metadata": { "editable": true }, @@ -506,7 +506,7 @@ }, { "cell_type": "markdown", - "id": "d1a2885a", + "id": "259e4f29", "metadata": { "editable": true }, @@ -526,7 +526,7 @@ }, { "cell_type": "markdown", - "id": "64b948e9", + "id": "8d1ef48b", "metadata": { "editable": true }, @@ -538,7 +538,7 @@ }, { "cell_type": "markdown", - "id": "424cd697", + "id": "ca5600f6", "metadata": { "editable": true }, @@ -553,7 +553,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "e4b9f801", + "id": "13aba5c0", "metadata": { "collapsed": false, "editable": true @@ -635,7 +635,7 @@ }, { "cell_type": "markdown", - "id": "7e8d1d9b", + "id": "88b9a399", "metadata": { "editable": true }, @@ -645,7 +645,7 @@ }, { "cell_type": "markdown", - "id": "3902f678", + "id": "759f93ac", "metadata": { "editable": true }, @@ -657,7 +657,7 @@ }, { "cell_type": "markdown", - "id": "b32729d6", + "id": "b7a93645", "metadata": { "editable": true }, @@ -667,7 +667,7 @@ }, { "cell_type": "markdown", - "id": "1040517d", + "id": "4ac35348", "metadata": { "editable": true }, @@ -678,7 +678,7 @@ }, { "cell_type": "markdown", - "id": "a5fe300b", + "id": "a6b0b9da", "metadata": { "editable": true }, @@ -690,7 +690,7 @@ }, { "cell_type": "markdown", - "id": "b42bede4", + "id": "678e9d77", "metadata": { "editable": true }, @@ -700,7 +700,7 @@ }, { "cell_type": "markdown", - "id": "dd4ef630", + "id": "e5516fd1", "metadata": { "editable": true }, @@ -712,7 +712,7 @@ }, { "cell_type": "markdown", - "id": "1637ce36", + "id": "1e7c9e7f", "metadata": { "editable": true }, @@ -722,7 +722,7 @@ }, { "cell_type": "markdown", - "id": "359da65f", + "id": "ecaeb187", "metadata": { "editable": true }, @@ -734,7 +734,7 @@ }, { "cell_type": "markdown", - "id": "7a2a8ded", + "id": "9c4d843f", "metadata": { "editable": true }, @@ -747,7 +747,7 @@ }, { "cell_type": "markdown", - "id": "f94c0601", + "id": "194e42e3", "metadata": { "editable": true }, @@ -759,7 +759,7 @@ }, { "cell_type": "markdown", - "id": "331a2eb8", + "id": "7cb92260", "metadata": { "editable": true }, @@ -769,7 +769,7 @@ }, { "cell_type": "markdown", - "id": "a7da4944", + "id": "cc62a0c1", "metadata": { "editable": true }, @@ -781,7 +781,7 @@ }, { "cell_type": "markdown", - "id": "115c35a0", + "id": "30a54b5d", "metadata": { "editable": true }, @@ -793,7 +793,7 @@ }, { "cell_type": "markdown", - "id": "e11e2f13", + "id": "13d9ab95", "metadata": { "editable": true }, @@ -804,7 +804,7 @@ }, { "cell_type": "markdown", - "id": "1856ce84", + "id": "56ee1b35", "metadata": { "editable": true }, @@ -816,7 +816,7 @@ }, { "cell_type": "markdown", - "id": "6b82f87b", + "id": "16f88407", "metadata": { "editable": true }, @@ -835,7 +835,7 @@ }, { "cell_type": "markdown", - "id": "33b1d7cb", + "id": "44b9b7c5", "metadata": { "editable": true }, @@ -848,7 +848,7 @@ }, { "cell_type": "markdown", - "id": "f315add2", + "id": "20b3490d", "metadata": { "editable": true }, @@ -858,7 +858,7 @@ }, { "cell_type": "markdown", - "id": "6a0abc23", + "id": "18a8e025", "metadata": { "editable": true }, @@ -870,7 +870,7 @@ }, { "cell_type": "markdown", - "id": "bc7438dc", + "id": "b1440e6a", "metadata": { "editable": true }, @@ -880,7 +880,7 @@ }, { "cell_type": "markdown", - "id": "9a47e07a", + "id": "bb929dfd", "metadata": { "editable": true }, @@ -892,7 +892,7 @@ }, { "cell_type": "markdown", - "id": "0858cac5", + "id": "4e135c3e", "metadata": { "editable": true }, @@ -902,7 +902,7 @@ }, { "cell_type": "markdown", - "id": "5351a875", + "id": "df0f404b", "metadata": { "editable": true }, @@ -914,7 +914,7 @@ }, { "cell_type": "markdown", - "id": "be8e16f7", + "id": "f86c15ab", "metadata": { "editable": true }, @@ -925,7 +925,7 @@ }, { "cell_type": "markdown", - "id": "2858ceb7", + "id": "d3ffaf34", "metadata": { "editable": true }, @@ -937,7 +937,7 @@ }, { "cell_type": "markdown", - "id": "14ac2764", + "id": "c5fdc06c", "metadata": { "editable": true }, @@ -947,7 +947,7 @@ }, { "cell_type": "markdown", - "id": "277b6a55", + "id": "c9f5090c", "metadata": { "editable": true }, @@ -959,7 +959,7 @@ }, { "cell_type": "markdown", - "id": "9f6cbddd", + "id": "e87b1f31", "metadata": { "editable": true }, @@ -969,7 +969,7 @@ }, { "cell_type": "markdown", - "id": "ce620b5c", + "id": "6e2773ee", "metadata": { "editable": true }, @@ -981,7 +981,7 @@ }, { "cell_type": "markdown", - "id": "48bed274", + "id": "d92309d9", "metadata": { "editable": true }, @@ -1002,7 +1002,7 @@ }, { "cell_type": "markdown", - "id": "e0da63bf", + "id": "d666c56b", "metadata": { "editable": true }, @@ -1029,7 +1029,7 @@ }, { "cell_type": "markdown", - "id": "9d844e47", + "id": "a8b96380", "metadata": { "editable": true }, @@ -1041,7 +1041,7 @@ }, { "cell_type": "markdown", - "id": "31b8b53d", + "id": "c9ed6485", "metadata": { "editable": true }, @@ -1053,7 +1053,7 @@ }, { "cell_type": "markdown", - "id": "c8e8ee22", + "id": "13e1f850", "metadata": { "editable": true }, @@ -1069,7 +1069,7 @@ }, { "cell_type": "markdown", - "id": "112c3851", + "id": "78b072dd", "metadata": { "editable": true }, @@ -1077,12 +1077,17 @@ "which is an $m\\times n$ matrix. If $\\boldsymbol{x}$ is a scalar, then the\n", "Jacobian is only a single-column vector, or an $m\\times 1$ matrix. If\n", "on the other hand $\\boldsymbol{y}$ is a scalar, the Jacobian becomes a\n", - "$1\\times n$ matrix." + "$1\\times n$ matrix.\n", + "\n", + "When this matrix is a square matrix $m=n$, its determinant is often referred to as the Jacobian\n", + "determinant. Both the matrix and (if $m=n$) the determinant are\n", + "often referred to simply as the Jacobian. The Jacobian matrix represents the differential of $\\boldsymbol{y}$ at every point where the\n", + "vector is differentiable." ] }, { "cell_type": "markdown", - "id": "29091702", + "id": "0fa7078d", "metadata": { "editable": true }, @@ -1094,7 +1099,7 @@ }, { "cell_type": "markdown", - "id": "5921c4c0", + "id": "cba4d76c", "metadata": { "editable": true }, @@ -1106,7 +1111,7 @@ }, { "cell_type": "markdown", - "id": "b4d433ce", + "id": "2ccd2390", "metadata": { "editable": true }, @@ -1117,7 +1122,7 @@ }, { "cell_type": "markdown", - "id": "e9f4bb68", + "id": "d209d4c6", "metadata": { "editable": true }, @@ -1129,7 +1134,7 @@ }, { "cell_type": "markdown", - "id": "4656a5ae", + "id": "77592a16", "metadata": { "editable": true }, @@ -1139,7 +1144,7 @@ }, { "cell_type": "markdown", - "id": "08880e1e", + "id": "981ee1e2", "metadata": { "editable": true }, @@ -1151,7 +1156,99 @@ }, { "cell_type": "markdown", - "id": "0623f4f2", + "id": "73e102a5", + "metadata": { + "editable": true + }, + "source": [ + "## Example 2\n", + "\n", + "We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications" + ] + }, + { + "cell_type": "markdown", + "id": "dad9ae06", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\alpha = \\boldsymbol{y}^T\\boldsymbol{A}\\boldsymbol{x}$,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f8a80467", + "metadata": { + "editable": true + }, + "source": [ + "with $\\boldsymbol{y}$ a vector of length $m$, $\\boldsymbol{A}$ an $m\\times n$ matrix and $\\boldsymbol{x}$ a vector of length $n$. We assume also that $\\boldsymbol{A}$ does not depend on any of the two vectors.\n", + "In order to find the derivative of $\\alpha$ with respect to the two vectors, we define an intermediate vector $\\boldsymbol{z}$. We define first\n", + "$\\boldsymbol{z}^T=\\boldsymbol{y}^T\\boldsymbol{A}$, a vector of length $n$. We have then" + ] + }, + { + "cell_type": "markdown", + "id": "65ded3d8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\alpha = \\boldsymbol{z}^T\\boldsymbol{x}$,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "eb8a2602", + "metadata": { + "editable": true + }, + "source": [ + "which means that (using our previous example) we have" + ] + }, + { + "cell_type": "markdown", + "id": "2351bdeb", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial \\alpha}{\\partial \\boldsymbol{x}} = \\boldsymbol{z}^T=\\boldsymbol{y}^T\\boldsymbol{A}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "851cf299", + "metadata": { + "editable": true + }, + "source": [ + "Since $\\alpha$ is a scalar we have $\\alpha =\\alpha^T=\\boldsymbol{x}^T\\boldsymbol{A}^T\\boldsymbol{y}$. Defining now $\\boldsymbol{z}=\\boldsymbol{x}^T\\boldsymbol{A}^T$ we find that" + ] + }, + { + "cell_type": "markdown", + "id": "d8bbd35f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial \\alpha}{\\partial \\boldsymbol{y}} = \\boldsymbol{z}^T=\\boldsymbol{x}^T\\boldsymbol{A}^T..\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7504cca3", "metadata": { "editable": true }, @@ -1163,7 +1260,7 @@ }, { "cell_type": "markdown", - "id": "1b4d4788", + "id": "34ce0544", "metadata": { "editable": true }, @@ -1175,7 +1272,7 @@ }, { "cell_type": "markdown", - "id": "5ffa77d2", + "id": "dbca73a6", "metadata": { "editable": true }, @@ -1187,7 +1284,7 @@ }, { "cell_type": "markdown", - "id": "e449fb3f", + "id": "4e10f1a4", "metadata": { "editable": true }, @@ -1199,7 +1296,7 @@ }, { "cell_type": "markdown", - "id": "ce40d458", + "id": "a098c345", "metadata": { "editable": true }, @@ -1209,7 +1306,7 @@ }, { "cell_type": "markdown", - "id": "09032e8a", + "id": "96e8625f", "metadata": { "editable": true }, @@ -1225,7 +1322,7 @@ }, { "cell_type": "markdown", - "id": "0febef6f", + "id": "37ac3110", "metadata": { "editable": true }, @@ -1237,7 +1334,7 @@ }, { "cell_type": "markdown", - "id": "58bce867", + "id": "3b8cb30c", "metadata": { "editable": true }, @@ -1247,7 +1344,7 @@ }, { "cell_type": "markdown", - "id": "f8fbefd3", + "id": "fdda24b3", "metadata": { "editable": true }, @@ -1259,7 +1356,7 @@ }, { "cell_type": "markdown", - "id": "0d330b80", + "id": "c904f55b", "metadata": { "editable": true }, @@ -1277,7 +1374,7 @@ }, { "cell_type": "markdown", - "id": "cc309220", + "id": "5f4ca832", "metadata": { "editable": true }, @@ -1288,7 +1385,7 @@ }, { "cell_type": "markdown", - "id": "8eb1e00f", + "id": "c02ddde4", "metadata": { "editable": true }, @@ -1300,7 +1397,7 @@ }, { "cell_type": "markdown", - "id": "763bdcc8", + "id": "76f264e7", "metadata": { "editable": true }, @@ -1310,7 +1407,7 @@ }, { "cell_type": "markdown", - "id": "11763e6b", + "id": "b403ae05", "metadata": { "editable": true }, @@ -1322,7 +1419,7 @@ }, { "cell_type": "markdown", - "id": "341dc56a", + "id": "91a6b9d3", "metadata": { "editable": true }, @@ -1332,7 +1429,7 @@ }, { "cell_type": "markdown", - "id": "7bcd7769", + "id": "b9f33c40", "metadata": { "editable": true }, @@ -1344,7 +1441,7 @@ }, { "cell_type": "markdown", - "id": "2ba30ee0", + "id": "868023cb", "metadata": { "editable": true }, @@ -1354,7 +1451,7 @@ }, { "cell_type": "markdown", - "id": "d30b103a", + "id": "56851ac5", "metadata": { "editable": true }, @@ -1368,7 +1465,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "07c65570", + "id": "5c436e24", "metadata": { "collapsed": false, "editable": true @@ -1383,7 +1480,7 @@ }, { "cell_type": "markdown", - "id": "ff0c8ae7", + "id": "46504e79", "metadata": { "editable": true }, @@ -1394,7 +1491,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "5738cb64", + "id": "be276da6", "metadata": { "collapsed": false, "editable": true @@ -1407,7 +1504,7 @@ }, { "cell_type": "markdown", - "id": "8063c994", + "id": "daa257d9", "metadata": { "editable": true }, @@ -1418,7 +1515,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "efb6044a", + "id": "79b4f4fb", "metadata": { "collapsed": false, "editable": true @@ -1441,7 +1538,7 @@ }, { "cell_type": "markdown", - "id": "a5ee6e08", + "id": "1555c9d2", "metadata": { "editable": true }, @@ -1455,7 +1552,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "39bc2995", + "id": "60be0677", "metadata": { "collapsed": false, "editable": true @@ -1468,7 +1565,7 @@ }, { "cell_type": "markdown", - "id": "b3163039", + "id": "0d4db9ce", "metadata": { "editable": true }, @@ -1479,7 +1576,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "8fe1005e", + "id": "7238c316", "metadata": { "collapsed": false, "editable": true @@ -1491,7 +1588,7 @@ }, { "cell_type": "markdown", - "id": "10357042", + "id": "ce4c2196", "metadata": { "editable": true }, @@ -1502,7 +1599,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "a6014a48", + "id": "1c06ad76", "metadata": { "collapsed": false, "editable": true @@ -1518,7 +1615,7 @@ }, { "cell_type": "markdown", - "id": "75f80804", + "id": "93828585", "metadata": { "editable": true }, @@ -1529,7 +1626,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "65656a4b", + "id": "b05ad916", "metadata": { "collapsed": false, "editable": true @@ -1543,7 +1640,7 @@ }, { "cell_type": "markdown", - "id": "076efb15", + "id": "e263ea05", "metadata": { "editable": true }, @@ -1564,7 +1661,7 @@ }, { "cell_type": "markdown", - "id": "2b116d45", + "id": "377d5aa2", "metadata": { "editable": true }, @@ -1575,7 +1672,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "d693a83b", + "id": "625a0465", "metadata": { "collapsed": false, "editable": true @@ -1624,7 +1721,7 @@ }, { "cell_type": "markdown", - "id": "922803d4", + "id": "f75c7d1a", "metadata": { "editable": true }, @@ -1635,7 +1732,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "ca2170d3", + "id": "6e6c4682", "metadata": { "collapsed": false, "editable": true @@ -1660,7 +1757,7 @@ }, { "cell_type": "markdown", - "id": "d50664cf", + "id": "c4502637", "metadata": { "editable": true }, @@ -1672,7 +1769,7 @@ }, { "cell_type": "markdown", - "id": "effa633b", + "id": "e89dd052", "metadata": { "editable": true }, @@ -1716,7 +1813,7 @@ }, { "cell_type": "markdown", - "id": "1f61b229", + "id": "13c4327f", "metadata": { "editable": true }, @@ -1728,7 +1825,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "6e9092c5", + "id": "12079ac7", "metadata": { "collapsed": false, "editable": true @@ -1744,7 +1841,7 @@ }, { "cell_type": "markdown", - "id": "7624c525", + "id": "7c4768ff", "metadata": { "editable": true }, @@ -1755,7 +1852,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "c9b45f28", + "id": "58f7605a", "metadata": { "collapsed": false, "editable": true @@ -1773,7 +1870,7 @@ }, { "cell_type": "markdown", - "id": "729068b9", + "id": "c7410df4", "metadata": { "editable": true }, @@ -1784,7 +1881,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "29e10e39", + "id": "5d536cc7", "metadata": { "collapsed": false, "editable": true @@ -1798,7 +1895,7 @@ }, { "cell_type": "markdown", - "id": "d95f84cc", + "id": "5304f077", "metadata": { "editable": true }, @@ -1809,7 +1906,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "42a4809f", + "id": "ef6e3fc6", "metadata": { "collapsed": false, "editable": true @@ -1822,7 +1919,7 @@ }, { "cell_type": "markdown", - "id": "246fad06", + "id": "85afc288", "metadata": { "editable": true }, @@ -1833,7 +1930,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "8ba59041", + "id": "182b4d41", "metadata": { "collapsed": false, "editable": true @@ -1850,7 +1947,7 @@ }, { "cell_type": "markdown", - "id": "5db136c1", + "id": "bb0c75e6", "metadata": { "editable": true }, @@ -1861,7 +1958,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "3b27503f", + "id": "2f265f98", "metadata": { "collapsed": false, "editable": true @@ -1877,7 +1974,7 @@ }, { "cell_type": "markdown", - "id": "803cbc6f", + "id": "08ced506", "metadata": { "editable": true }, @@ -1888,7 +1985,7 @@ { "cell_type": "code", "execution_count": 17, - "id": "20c209d9", + "id": "3503ba4a", "metadata": { "collapsed": false, "editable": true @@ -1912,7 +2009,7 @@ }, { "cell_type": "markdown", - "id": "376f8747", + "id": "3c1d06b1", "metadata": { "editable": true }, @@ -1923,7 +2020,7 @@ { "cell_type": "code", "execution_count": 18, - "id": "28f2e6af", + "id": "79882da9", "metadata": { "collapsed": false, "editable": true @@ -1936,7 +2033,7 @@ }, { "cell_type": "markdown", - "id": "483b3929", + "id": "900970ed", "metadata": { "editable": true }, @@ -1947,7 +2044,7 @@ { "cell_type": "code", "execution_count": 19, - "id": "f8f3323b", + "id": "d00ffb03", "metadata": { "collapsed": false, "editable": true @@ -1967,7 +2064,7 @@ }, { "cell_type": "markdown", - "id": "7e0d4a52", + "id": "df44d22d", "metadata": { "editable": true }, @@ -1978,7 +2075,7 @@ { "cell_type": "code", "execution_count": 20, - "id": "f8fcb897", + "id": "5ff0eb5e", "metadata": { "collapsed": false, "editable": true @@ -2021,7 +2118,7 @@ { "cell_type": "code", "execution_count": 21, - "id": "7ee8acf9", + "id": "fa13953d", "metadata": { "collapsed": false, "editable": true @@ -2036,7 +2133,7 @@ }, { "cell_type": "markdown", - "id": "58fce880", + "id": "b6dcdb6e", "metadata": { "editable": true }, @@ -2065,7 +2162,7 @@ }, { "cell_type": "markdown", - "id": "806ffde3", + "id": "1bb84244", "metadata": { "editable": true }, @@ -2090,7 +2187,7 @@ }, { "cell_type": "markdown", - "id": "9747cabf", + "id": "1ca1a49e", "metadata": { "editable": true }, @@ -2110,7 +2207,7 @@ }, { "cell_type": "markdown", - "id": "ce766c03", + "id": "9b612d9e", "metadata": { "editable": true }, @@ -2137,7 +2234,7 @@ }, { "cell_type": "markdown", - "id": "5d002829", + "id": "47d66f07", "metadata": { "editable": true }, @@ -2150,7 +2247,7 @@ }, { "cell_type": "markdown", - "id": "2cce1e61", + "id": "1b4f094d", "metadata": { "editable": true }, @@ -2162,7 +2259,7 @@ }, { "cell_type": "markdown", - "id": "8be386f7", + "id": "39d64f3e", "metadata": { "editable": true }, @@ -2173,7 +2270,7 @@ }, { "cell_type": "markdown", - "id": "bd19f379", + "id": "81c9ac1d", "metadata": { "editable": true }, @@ -2189,7 +2286,7 @@ { "cell_type": "code", "execution_count": 22, - "id": "7e06104f", + "id": "f35cfb77", "metadata": { "collapsed": false, "editable": true @@ -2223,7 +2320,7 @@ }, { "cell_type": "markdown", - "id": "0d903673", + "id": "a8d95074", "metadata": { "editable": true }, @@ -2233,7 +2330,7 @@ }, { "cell_type": "markdown", - "id": "f6aa52e2", + "id": "34dc1253", "metadata": { "editable": true }, @@ -2248,7 +2345,7 @@ }, { "cell_type": "markdown", - "id": "b768c5e4", + "id": "21b5863c", "metadata": { "editable": true }, @@ -2260,7 +2357,7 @@ }, { "cell_type": "markdown", - "id": "98bf7840", + "id": "dc5cbf4d", "metadata": { "editable": true }, @@ -2270,7 +2367,7 @@ }, { "cell_type": "markdown", - "id": "a81ac118", + "id": "53a0794d", "metadata": { "editable": true }, @@ -2286,7 +2383,7 @@ { "cell_type": "code", "execution_count": 23, - "id": "becefd95", + "id": "42e0801a", "metadata": { "collapsed": false, "editable": true @@ -2303,7 +2400,7 @@ }, { "cell_type": "markdown", - "id": "c3f39eaf", + "id": "b147e712", "metadata": { "editable": true }, @@ -2316,7 +2413,7 @@ { "cell_type": "code", "execution_count": 24, - "id": "aaf6e665", + "id": "25cf0260", "metadata": { "collapsed": false, "editable": true @@ -2363,7 +2460,7 @@ }, { "cell_type": "markdown", - "id": "7a0e2784", + "id": "cf0c1eda", "metadata": { "editable": true }, @@ -2374,7 +2471,7 @@ { "cell_type": "code", "execution_count": 25, - "id": "905a7403", + "id": "0c52272d", "metadata": { "collapsed": false, "editable": true @@ -2477,7 +2574,7 @@ }, { "cell_type": "markdown", - "id": "438c50fc", + "id": "4a8ab7e3", "metadata": { "editable": true }, @@ -2487,7 +2584,7 @@ }, { "cell_type": "markdown", - "id": "42dfb2e3", + "id": "cc73b010", "metadata": { "editable": true }, @@ -2501,7 +2598,7 @@ }, { "cell_type": "markdown", - "id": "7cc86bb5", + "id": "7e7d2aab", "metadata": { "editable": true }, @@ -2513,7 +2610,7 @@ }, { "cell_type": "markdown", - "id": "83fc723c", + "id": "a0372670", "metadata": { "editable": true }, @@ -2525,7 +2622,7 @@ }, { "cell_type": "markdown", - "id": "406aa8dd", + "id": "4eb19692", "metadata": { "editable": true }, @@ -2537,7 +2634,7 @@ }, { "cell_type": "markdown", - "id": "67f52d00", + "id": "7e2d6b43", "metadata": { "editable": true }, @@ -2547,7 +2644,7 @@ }, { "cell_type": "markdown", - "id": "af039735", + "id": "2a9e0cac", "metadata": { "editable": true }, @@ -2559,7 +2656,7 @@ }, { "cell_type": "markdown", - "id": "d5e5621a", + "id": "f6027a54", "metadata": { "editable": true }, @@ -2569,7 +2666,7 @@ }, { "cell_type": "markdown", - "id": "d832b987", + "id": "54e381e4", "metadata": { "editable": true }, @@ -2581,7 +2678,7 @@ }, { "cell_type": "markdown", - "id": "456c770b", + "id": "fb1eff94", "metadata": { "editable": true }, @@ -2592,7 +2689,7 @@ }, { "cell_type": "markdown", - "id": "e78ee034", + "id": "5cd64619", "metadata": { "editable": true }, @@ -2604,7 +2701,7 @@ }, { "cell_type": "markdown", - "id": "3074b255", + "id": "175880bf", "metadata": { "editable": true }, @@ -2616,7 +2713,7 @@ }, { "cell_type": "markdown", - "id": "b9e5b517", + "id": "f007f488", "metadata": { "editable": true }, @@ -2626,7 +2723,7 @@ }, { "cell_type": "markdown", - "id": "61d57ad2", + "id": "20dbb342", "metadata": { "editable": true }, @@ -2638,7 +2735,7 @@ }, { "cell_type": "markdown", - "id": "b0d206f9", + "id": "bfcf4660", "metadata": { "editable": true }, @@ -2650,7 +2747,7 @@ }, { "cell_type": "markdown", - "id": "9689cbee", + "id": "34ff3e7f", "metadata": { "editable": true }, @@ -2660,7 +2757,7 @@ }, { "cell_type": "markdown", - "id": "2fbc8dab", + "id": "d941bc3b", "metadata": { "editable": true }, @@ -2672,7 +2769,7 @@ }, { "cell_type": "markdown", - "id": "1e500c3f", + "id": "dc14f3a0", "metadata": { "editable": true }, @@ -2682,7 +2779,7 @@ }, { "cell_type": "markdown", - "id": "cfa13551", + "id": "2f36ca32", "metadata": { "editable": true }, @@ -2694,7 +2791,7 @@ }, { "cell_type": "markdown", - "id": "1f1466c5", + "id": "b9f7626a", "metadata": { "editable": true }, @@ -2704,7 +2801,7 @@ }, { "cell_type": "markdown", - "id": "bf34f6fa", + "id": "b398c24b", "metadata": { "editable": true }, @@ -2744,7 +2841,7 @@ }, { "cell_type": "markdown", - "id": "6ddcc022", + "id": "e0d6a24a", "metadata": { "editable": true }, @@ -2761,7 +2858,7 @@ }, { "cell_type": "markdown", - "id": "0cf69ea3", + "id": "5daebff5", "metadata": { "editable": true }, @@ -2784,7 +2881,7 @@ }, { "cell_type": "markdown", - "id": "b4268613", + "id": "8e334530", "metadata": { "editable": true }, @@ -2801,7 +2898,7 @@ }, { "cell_type": "markdown", - "id": "9046cf24", + "id": "8d65cc3c", "metadata": { "editable": true }, @@ -2820,7 +2917,7 @@ }, { "cell_type": "markdown", - "id": "4e91a577", + "id": "6141f5d5", "metadata": { "editable": true }, @@ -2831,7 +2928,7 @@ }, { "cell_type": "markdown", - "id": "3a9f2cdc", + "id": "00a43a59", "metadata": { "editable": true }, @@ -2843,7 +2940,7 @@ }, { "cell_type": "markdown", - "id": "66788c79", + "id": "5a4c6fb9", "metadata": { "editable": true }, @@ -2861,7 +2958,7 @@ }, { "cell_type": "markdown", - "id": "2f1d2f0a", + "id": "b25d2406", "metadata": { "editable": true }, @@ -2877,7 +2974,7 @@ }, { "cell_type": "markdown", - "id": "27371195", + "id": "d92354ce", "metadata": { "editable": true }, @@ -2889,7 +2986,7 @@ }, { "cell_type": "markdown", - "id": "28ed8a1a", + "id": "167490b4", "metadata": { "editable": true }, @@ -2899,7 +2996,7 @@ }, { "cell_type": "markdown", - "id": "55fdcad1", + "id": "c35c2486", "metadata": { "editable": true }, @@ -2914,7 +3011,7 @@ }, { "cell_type": "markdown", - "id": "16f34838", + "id": "02d37085", "metadata": { "editable": true }, @@ -2926,7 +3023,7 @@ }, { "cell_type": "markdown", - "id": "09503520", + "id": "c4da0f4f", "metadata": { "editable": true }, @@ -2936,7 +3033,7 @@ }, { "cell_type": "markdown", - "id": "2d6682ee", + "id": "d54f9e2e", "metadata": { "editable": true }, @@ -2948,7 +3045,7 @@ }, { "cell_type": "markdown", - "id": "5bd76fc1", + "id": "07f52198", "metadata": { "editable": true }, @@ -2958,7 +3055,7 @@ }, { "cell_type": "markdown", - "id": "3c7c8089", + "id": "36ace111", "metadata": { "editable": true }, @@ -2970,7 +3067,7 @@ }, { "cell_type": "markdown", - "id": "726c5981", + "id": "29fd9cb8", "metadata": { "editable": true }, @@ -2982,7 +3079,7 @@ }, { "cell_type": "markdown", - "id": "2496c4e4", + "id": "b42e3e8d", "metadata": { "editable": true }, @@ -2997,7 +3094,7 @@ }, { "cell_type": "markdown", - "id": "7c47fc1b", + "id": "b7da9d82", "metadata": { "editable": true }, @@ -3008,7 +3105,7 @@ }, { "cell_type": "markdown", - "id": "21428876", + "id": "e9ca5281", "metadata": { "editable": true }, @@ -3028,7 +3125,7 @@ }, { "cell_type": "markdown", - "id": "628da455", + "id": "36fd9455", "metadata": { "editable": true }, @@ -3040,7 +3137,7 @@ }, { "cell_type": "markdown", - "id": "69e0b0d8", + "id": "b00ef620", "metadata": { "editable": true }, @@ -3050,7 +3147,7 @@ }, { "cell_type": "markdown", - "id": "e684f1d4", + "id": "2921ba56", "metadata": { "editable": true }, @@ -3062,7 +3159,7 @@ }, { "cell_type": "markdown", - "id": "297a174d", + "id": "ff52d950", "metadata": { "editable": true }, @@ -3091,7 +3188,7 @@ }, { "cell_type": "markdown", - "id": "783a40f5", + "id": "298cd537", "metadata": { "editable": true }, @@ -3118,7 +3215,7 @@ }, { "cell_type": "markdown", - "id": "46b81f95", + "id": "076a41ee", "metadata": { "editable": true }, @@ -3129,7 +3226,7 @@ { "cell_type": "code", "execution_count": 26, - "id": "cf341757", + "id": "fe37d1c3", "metadata": { "collapsed": false, "editable": true @@ -3169,7 +3266,7 @@ }, { "cell_type": "markdown", - "id": "bf70bf90", + "id": "6a4c378a", "metadata": { "editable": true }, @@ -3186,7 +3283,7 @@ }, { "cell_type": "markdown", - "id": "a73c1f8d", + "id": "e87182c9", "metadata": { "editable": true }, @@ -3209,7 +3306,7 @@ }, { "cell_type": "markdown", - "id": "10bf5ca0", + "id": "9ad2298e", "metadata": { "editable": true }, @@ -3223,7 +3320,7 @@ }, { "cell_type": "markdown", - "id": "85061039", + "id": "e111dea2", "metadata": { "editable": true }, @@ -3242,7 +3339,7 @@ }, { "cell_type": "markdown", - "id": "c910b923", + "id": "979ea846", "metadata": { "editable": true }, @@ -3252,7 +3349,7 @@ }, { "cell_type": "markdown", - "id": "f876a6fa", + "id": "8ff6ad7f", "metadata": { "editable": true }, @@ -3264,7 +3361,7 @@ }, { "cell_type": "markdown", - "id": "ea5895c8", + "id": "54ea3d6d", "metadata": { "editable": true }, @@ -3278,7 +3375,7 @@ }, { "cell_type": "markdown", - "id": "3be8ed04", + "id": "5bff1780", "metadata": { "editable": true }, @@ -3290,7 +3387,7 @@ }, { "cell_type": "markdown", - "id": "e95c8816", + "id": "6ba58ba3", "metadata": { "editable": true }, @@ -3300,7 +3397,7 @@ }, { "cell_type": "markdown", - "id": "88468938", + "id": "8fc21b19", "metadata": { "editable": true }, @@ -3312,7 +3409,7 @@ }, { "cell_type": "markdown", - "id": "9a19b640", + "id": "611cdb92", "metadata": { "editable": true }, @@ -3329,7 +3426,7 @@ }, { "cell_type": "markdown", - "id": "59473174", + "id": "3ad8e6f1", "metadata": { "editable": true }, @@ -3339,7 +3436,7 @@ }, { "cell_type": "markdown", - "id": "90bbb36f", + "id": "bea70938", "metadata": { "editable": true }, @@ -3355,7 +3452,7 @@ }, { "cell_type": "markdown", - "id": "5cc4cd65", + "id": "f18e5b15", "metadata": { "editable": true }, @@ -3365,7 +3462,7 @@ }, { "cell_type": "markdown", - "id": "e9913e93", + "id": "8641d523", "metadata": { "editable": true }, @@ -3381,7 +3478,7 @@ }, { "cell_type": "markdown", - "id": "d4d860b2", + "id": "bbebf273", "metadata": { "editable": true }, @@ -3391,7 +3488,7 @@ }, { "cell_type": "markdown", - "id": "0ea33681", + "id": "d9ed8dcf", "metadata": { "editable": true }, @@ -3407,7 +3504,7 @@ }, { "cell_type": "markdown", - "id": "d1229bd7", + "id": "b98fcae8", "metadata": { "editable": true }, @@ -3417,7 +3514,7 @@ }, { "cell_type": "markdown", - "id": "39c6e080", + "id": "41719275", "metadata": { "editable": true }, @@ -3434,7 +3531,7 @@ }, { "cell_type": "markdown", - "id": "4b6dc63f", + "id": "264f61ab", "metadata": { "editable": true }, @@ -3446,7 +3543,7 @@ }, { "cell_type": "markdown", - "id": "5085d614", + "id": "b909cc00", "metadata": { "editable": true }, @@ -3458,7 +3555,7 @@ }, { "cell_type": "markdown", - "id": "e1489aee", + "id": "4620a4fa", "metadata": { "editable": true }, @@ -3470,7 +3567,7 @@ }, { "cell_type": "markdown", - "id": "a779fe81", + "id": "d920dc12", "metadata": { "editable": true }, @@ -3480,7 +3577,7 @@ }, { "cell_type": "markdown", - "id": "2e1a8999", + "id": "857c104d", "metadata": { "editable": true }, @@ -3492,7 +3589,7 @@ }, { "cell_type": "markdown", - "id": "e9afe762", + "id": "df8256ca", "metadata": { "editable": true }, @@ -3504,7 +3601,7 @@ }, { "cell_type": "markdown", - "id": "a53312df", + "id": "3f8cf389", "metadata": { "editable": true }, @@ -3516,7 +3613,7 @@ }, { "cell_type": "markdown", - "id": "4fcf6b60", + "id": "ce67d743", "metadata": { "editable": true }, @@ -3526,7 +3623,7 @@ }, { "cell_type": "markdown", - "id": "c0f1802d", + "id": "30189ac0", "metadata": { "editable": true }, @@ -3538,7 +3635,7 @@ }, { "cell_type": "markdown", - "id": "2f3d5b6b", + "id": "eaa2f222", "metadata": { "editable": true }, @@ -3548,7 +3645,7 @@ }, { "cell_type": "markdown", - "id": "803d0009", + "id": "bcce40a1", "metadata": { "editable": true }, @@ -3560,7 +3657,7 @@ }, { "cell_type": "markdown", - "id": "ae47bb5f", + "id": "4a3898c7", "metadata": { "editable": true }, @@ -3574,7 +3671,7 @@ }, { "cell_type": "markdown", - "id": "6bb81684", + "id": "005c0cc5", "metadata": { "editable": true }, @@ -3586,7 +3683,7 @@ }, { "cell_type": "markdown", - "id": "d6a1a850", + "id": "ed0ef6d8", "metadata": { "editable": true }, @@ -3598,7 +3695,7 @@ }, { "cell_type": "markdown", - "id": "2c7dd08f", + "id": "c29b386b", "metadata": { "editable": true }, @@ -3608,7 +3705,7 @@ }, { "cell_type": "markdown", - "id": "41bb0c81", + "id": "0e7f4695", "metadata": { "editable": true }, @@ -3620,7 +3717,7 @@ }, { "cell_type": "markdown", - "id": "494c8770", + "id": "c6b43df3", "metadata": { "editable": true }, @@ -3631,7 +3728,7 @@ }, { "cell_type": "markdown", - "id": "dea5fb5a", + "id": "b45b5e09", "metadata": { "editable": true }, @@ -3643,7 +3740,7 @@ }, { "cell_type": "markdown", - "id": "dcbb67ae", + "id": "711ccb17", "metadata": { "editable": true }, @@ -3653,7 +3750,7 @@ }, { "cell_type": "markdown", - "id": "bdd7866e", + "id": "1dcbc546", "metadata": { "editable": true }, @@ -3665,7 +3762,7 @@ }, { "cell_type": "markdown", - "id": "bc75c051", + "id": "81232ccf", "metadata": { "editable": true }, @@ -3675,7 +3772,7 @@ }, { "cell_type": "markdown", - "id": "019a2c76", + "id": "a4de4fc7", "metadata": { "editable": true }, @@ -3687,7 +3784,7 @@ }, { "cell_type": "markdown", - "id": "1dfde562", + "id": "813b3db2", "metadata": { "editable": true }, @@ -3698,7 +3795,7 @@ }, { "cell_type": "markdown", - "id": "b2bc4f99", + "id": "00fc0420", "metadata": { "editable": true }, @@ -3710,7 +3807,7 @@ }, { "cell_type": "markdown", - "id": "5936aa08", + "id": "9f6a9fc6", "metadata": { "editable": true }, @@ -3728,7 +3825,7 @@ }, { "cell_type": "markdown", - "id": "ca751aae", + "id": "5289b513", "metadata": { "editable": true }, @@ -3744,7 +3841,7 @@ }, { "cell_type": "markdown", - "id": "36d16e4f", + "id": "86378085", "metadata": { "editable": true }, @@ -3756,7 +3853,7 @@ }, { "cell_type": "markdown", - "id": "02c5b006", + "id": "721b0b0b", "metadata": { "editable": true }, @@ -3768,7 +3865,7 @@ }, { "cell_type": "markdown", - "id": "34d19a5d", + "id": "2b4b32fe", "metadata": { "editable": true }, @@ -3780,7 +3877,7 @@ }, { "cell_type": "markdown", - "id": "f3aef9cc", + "id": "8ff859ac", "metadata": { "editable": true }, @@ -3793,7 +3890,7 @@ }, { "cell_type": "markdown", - "id": "104ce871", + "id": "033e9ad3", "metadata": { "editable": true }, @@ -3809,7 +3906,7 @@ }, { "cell_type": "markdown", - "id": "e615d613", + "id": "b36c9b65", "metadata": { "editable": true }, @@ -3823,7 +3920,7 @@ }, { "cell_type": "markdown", - "id": "89fac8ef", + "id": "3ba34b11", "metadata": { "editable": true }, @@ -3833,7 +3930,7 @@ }, { "cell_type": "markdown", - "id": "a3605ede", + "id": "56e2c38d", "metadata": { "editable": true }, @@ -3845,7 +3942,7 @@ }, { "cell_type": "markdown", - "id": "e11fe9c0", + "id": "b35ff1c6", "metadata": { "editable": true }, @@ -3855,7 +3952,7 @@ }, { "cell_type": "markdown", - "id": "97304c79", + "id": "fa26ee6b", "metadata": { "editable": true }, @@ -3867,7 +3964,7 @@ }, { "cell_type": "markdown", - "id": "b75e6d3f", + "id": "7fe97aeb", "metadata": { "editable": true }, @@ -3877,7 +3974,7 @@ }, { "cell_type": "markdown", - "id": "c1ad74b4", + "id": "3155eb87", "metadata": { "editable": true }, @@ -3891,7 +3988,7 @@ }, { "cell_type": "markdown", - "id": "18685460", + "id": "7d6d494e", "metadata": { "editable": true }, @@ -3908,7 +4005,7 @@ }, { "cell_type": "markdown", - "id": "5c5e287e", + "id": "c0bbe0a8", "metadata": { "editable": true }, @@ -3924,7 +4021,7 @@ }, { "cell_type": "markdown", - "id": "d3fdf3fb", + "id": "25ad30fd", "metadata": { "editable": true }, @@ -3936,7 +4033,7 @@ }, { "cell_type": "markdown", - "id": "b0bdec8a", + "id": "91f63f4e", "metadata": { "editable": true }, @@ -3949,7 +4046,7 @@ }, { "cell_type": "markdown", - "id": "d00514ea", + "id": "6c4815c9", "metadata": { "editable": true }, @@ -3963,7 +4060,7 @@ }, { "cell_type": "markdown", - "id": "a9ece68d", + "id": "87265840", "metadata": { "editable": true }, @@ -3973,7 +4070,7 @@ }, { "cell_type": "markdown", - "id": "dc69f38f", + "id": "b0500cde", "metadata": { "editable": true }, @@ -3986,7 +4083,7 @@ }, { "cell_type": "markdown", - "id": "f0688117", + "id": "2a6ed2aa", "metadata": { "editable": true }, @@ -4005,7 +4102,7 @@ }, { "cell_type": "markdown", - "id": "c4bd6a07", + "id": "224198d4", "metadata": { "editable": true }, @@ -4017,7 +4114,7 @@ }, { "cell_type": "markdown", - "id": "fbc22dbe", + "id": "41c99c94", "metadata": { "editable": true }, @@ -4029,7 +4126,7 @@ }, { "cell_type": "markdown", - "id": "2e897fdf", + "id": "394538ae", "metadata": { "editable": true }, @@ -4039,7 +4136,7 @@ }, { "cell_type": "markdown", - "id": "edfa5568", + "id": "1241aed5", "metadata": { "editable": true }, @@ -4051,7 +4148,7 @@ }, { "cell_type": "markdown", - "id": "724c9ccc", + "id": "ebdc24a9", "metadata": { "editable": true }, @@ -4064,7 +4161,7 @@ }, { "cell_type": "markdown", - "id": "eef4be52", + "id": "5d2a5c77", "metadata": { "editable": true }, @@ -4083,7 +4180,7 @@ }, { "cell_type": "markdown", - "id": "ac767a45", + "id": "44849d96", "metadata": { "editable": true }, @@ -4093,7 +4190,7 @@ }, { "cell_type": "markdown", - "id": "f5f420c2", + "id": "f8055506", "metadata": { "editable": true }, @@ -4112,7 +4209,7 @@ }, { "cell_type": "markdown", - "id": "c9c4959d", + "id": "59133969", "metadata": { "editable": true }, @@ -4130,7 +4227,7 @@ }, { "cell_type": "markdown", - "id": "eafd6e6d", + "id": "4eaa4ed0", "metadata": { "editable": true }, @@ -4144,7 +4241,7 @@ }, { "cell_type": "markdown", - "id": "42f20e92", + "id": "d26d6e0f", "metadata": { "editable": true }, @@ -4159,7 +4256,7 @@ { "cell_type": "code", "execution_count": 27, - "id": "f813e53e", + "id": "cdea11b4", "metadata": { "collapsed": false, "editable": true @@ -4180,7 +4277,7 @@ }, { "cell_type": "markdown", - "id": "247471e4", + "id": "ea0ba4fc", "metadata": { "editable": true }, @@ -4197,7 +4294,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "d2c36e83", + "id": "36ca25af", "metadata": { "collapsed": false, "editable": true @@ -4229,7 +4326,7 @@ }, { "cell_type": "markdown", - "id": "41002463", + "id": "dd2c3961", "metadata": { "editable": true }, @@ -4243,7 +4340,7 @@ }, { "cell_type": "markdown", - "id": "56c99f24", + "id": "f69e7d63", "metadata": { "editable": true }, @@ -4256,7 +4353,7 @@ { "cell_type": "code", "execution_count": 29, - "id": "38ad5db6", + "id": "af5d97db", "metadata": { "collapsed": false, "editable": true @@ -4281,7 +4378,7 @@ }, { "cell_type": "markdown", - "id": "3121879d", + "id": "80a55021", "metadata": { "editable": true }, @@ -4291,7 +4388,7 @@ }, { "cell_type": "markdown", - "id": "a69a358d", + "id": "3e7312e3", "metadata": { "editable": true }, @@ -4302,7 +4399,7 @@ { "cell_type": "code", "execution_count": 30, - "id": "148e9543", + "id": "2f42578e", "metadata": { "collapsed": false, "editable": true @@ -4356,7 +4453,7 @@ }, { "cell_type": "markdown", - "id": "17aff9a1", + "id": "b7f1b2d1", "metadata": { "editable": true }, @@ -4373,7 +4470,7 @@ }, { "cell_type": "markdown", - "id": "35e1797a", + "id": "7b576acb", "metadata": { "editable": true }, @@ -4385,7 +4482,7 @@ }, { "cell_type": "markdown", - "id": "252fca16", + "id": "5a15b5f3", "metadata": { "editable": true }, @@ -4397,7 +4494,7 @@ }, { "cell_type": "markdown", - "id": "8732dca9", + "id": "fe08a1e5", "metadata": { "editable": true }, @@ -4407,7 +4504,7 @@ }, { "cell_type": "markdown", - "id": "5d4d1274", + "id": "9f5a3746", "metadata": { "editable": true }, @@ -4424,7 +4521,7 @@ }, { "cell_type": "markdown", - "id": "ee873312", + "id": "3393423b", "metadata": { "editable": true }, @@ -4434,7 +4531,7 @@ }, { "cell_type": "markdown", - "id": "2497d2d4", + "id": "bc030494", "metadata": { "editable": true }, @@ -4449,7 +4546,7 @@ }, { "cell_type": "markdown", - "id": "c66343ac", + "id": "f3ad2858", "metadata": { "editable": true }, @@ -4459,7 +4556,7 @@ }, { "cell_type": "markdown", - "id": "286af61f", + "id": "47a3df49", "metadata": { "editable": true }, @@ -4473,7 +4570,7 @@ }, { "cell_type": "markdown", - "id": "1c409c5f", + "id": "131f3b24", "metadata": { "editable": true }, @@ -4485,7 +4582,7 @@ }, { "cell_type": "markdown", - "id": "61165d5d", + "id": "b8614cf9", "metadata": { "editable": true }, @@ -4497,7 +4594,7 @@ }, { "cell_type": "markdown", - "id": "fe288d2c", + "id": "ad3d9a7b", "metadata": { "editable": true }, @@ -4509,7 +4606,7 @@ }, { "cell_type": "markdown", - "id": "5410d061", + "id": "a4d99c9f", "metadata": { "editable": true }, @@ -4519,7 +4616,7 @@ }, { "cell_type": "markdown", - "id": "b546868b", + "id": "67e5cf1f", "metadata": { "editable": true }, @@ -4531,7 +4628,7 @@ }, { "cell_type": "markdown", - "id": "6eb95db8", + "id": "84c20aed", "metadata": { "editable": true }, @@ -4541,7 +4638,7 @@ }, { "cell_type": "markdown", - "id": "bd9a4a9d", + "id": "a09454a5", "metadata": { "editable": true }, @@ -4558,7 +4655,7 @@ }, { "cell_type": "markdown", - "id": "266910cb", + "id": "e345c3fb", "metadata": { "editable": true }, @@ -4568,7 +4665,7 @@ }, { "cell_type": "markdown", - "id": "5f200279", + "id": "5dcec973", "metadata": { "editable": true }, @@ -4580,7 +4677,7 @@ }, { "cell_type": "markdown", - "id": "60af6314", + "id": "c1045673", "metadata": { "editable": true }, @@ -4590,7 +4687,7 @@ }, { "cell_type": "markdown", - "id": "b96e6fdc", + "id": "c831c8f5", "metadata": { "editable": true }, @@ -4602,7 +4699,7 @@ }, { "cell_type": "markdown", - "id": "e1b333c3", + "id": "a8cd802a", "metadata": { "editable": true }, @@ -4616,7 +4713,7 @@ }, { "cell_type": "markdown", - "id": "0542f076", + "id": "ae3f36d4", "metadata": { "editable": true }, @@ -4628,7 +4725,7 @@ }, { "cell_type": "markdown", - "id": "6fa8ee09", + "id": "c8ad4cdf", "metadata": { "editable": true }, @@ -4650,7 +4747,7 @@ }, { "cell_type": "markdown", - "id": "946c5371", + "id": "8cb19611", "metadata": { "editable": true }, @@ -4662,7 +4759,7 @@ }, { "cell_type": "markdown", - "id": "5389bab4", + "id": "2e96da80", "metadata": { "editable": true }, @@ -4677,7 +4774,7 @@ }, { "cell_type": "markdown", - "id": "d18a088f", + "id": "5da8a140", "metadata": { "editable": true }, @@ -4689,7 +4786,7 @@ }, { "cell_type": "markdown", - "id": "1b010eb0", + "id": "db1c8351", "metadata": { "editable": true }, @@ -4701,7 +4798,7 @@ }, { "cell_type": "markdown", - "id": "a99445fa", + "id": "d4353fe9", "metadata": { "editable": true }, @@ -4711,7 +4808,7 @@ }, { "cell_type": "markdown", - "id": "642cc835", + "id": "55a5b10a", "metadata": { "editable": true }, @@ -4723,7 +4820,7 @@ }, { "cell_type": "markdown", - "id": "1247e26a", + "id": "eaddf5e1", "metadata": { "editable": true }, @@ -4733,7 +4830,7 @@ }, { "cell_type": "markdown", - "id": "f0e57efa", + "id": "000d822e", "metadata": { "editable": true }, @@ -4745,7 +4842,7 @@ }, { "cell_type": "markdown", - "id": "b2d9771d", + "id": "b37d6991", "metadata": { "editable": true }, @@ -4755,7 +4852,7 @@ }, { "cell_type": "markdown", - "id": "467c11e6", + "id": "d5efc1f3", "metadata": { "editable": true }, @@ -4767,7 +4864,7 @@ }, { "cell_type": "markdown", - "id": "e48b6a92", + "id": "a698d2f3", "metadata": { "editable": true }, @@ -4784,7 +4881,7 @@ }, { "cell_type": "markdown", - "id": "05b57e15", + "id": "7b238ad6", "metadata": { "editable": true }, @@ -4797,7 +4894,7 @@ }, { "cell_type": "markdown", - "id": "2f8aeb1c", + "id": "da794348", "metadata": { "editable": true }, @@ -4809,7 +4906,7 @@ }, { "cell_type": "markdown", - "id": "70af1652", + "id": "4d0791ea", "metadata": { "editable": true }, @@ -4819,7 +4916,7 @@ }, { "cell_type": "markdown", - "id": "75c32ff6", + "id": "1a931ed8", "metadata": { "editable": true }, @@ -4832,7 +4929,7 @@ }, { "cell_type": "markdown", - "id": "73e17b6e", + "id": "2c071c19", "metadata": { "editable": true }, @@ -4842,7 +4939,7 @@ }, { "cell_type": "markdown", - "id": "2be67f9c", + "id": "6ad3f22e", "metadata": { "editable": true }, @@ -4854,7 +4951,7 @@ }, { "cell_type": "markdown", - "id": "0534d345", + "id": "0685c48f", "metadata": { "editable": true }, @@ -4867,7 +4964,7 @@ }, { "cell_type": "markdown", - "id": "8b76b1a3", + "id": "aff97511", "metadata": { "editable": true }, @@ -4880,7 +4977,7 @@ }, { "cell_type": "markdown", - "id": "a47dc6ec", + "id": "520399fb", "metadata": { "editable": true }, @@ -4892,7 +4989,7 @@ }, { "cell_type": "markdown", - "id": "34552a19", + "id": "9de627ae", "metadata": { "editable": true }, @@ -4904,7 +5001,7 @@ }, { "cell_type": "markdown", - "id": "d5d0b8e0", + "id": "284d273d", "metadata": { "editable": true }, @@ -4914,7 +5011,7 @@ }, { "cell_type": "markdown", - "id": "2d8d93b2", + "id": "491bc6a6", "metadata": { "editable": true }, @@ -4927,7 +5024,7 @@ }, { "cell_type": "markdown", - "id": "6adbf0a8", + "id": "08d17566", "metadata": { "editable": true }, @@ -4939,7 +5036,7 @@ }, { "cell_type": "markdown", - "id": "03e7f601", + "id": "ae4880c4", "metadata": { "editable": true }, @@ -4951,7 +5048,7 @@ }, { "cell_type": "markdown", - "id": "fef5b35c", + "id": "e00a0816", "metadata": { "editable": true }, @@ -4963,7 +5060,7 @@ }, { "cell_type": "markdown", - "id": "af511d88", + "id": "58eaaad3", "metadata": { "editable": true }, @@ -4975,7 +5072,7 @@ }, { "cell_type": "markdown", - "id": "c478e5b3", + "id": "1b82e9f1", "metadata": { "editable": true }, @@ -4989,7 +5086,7 @@ }, { "cell_type": "markdown", - "id": "197d450d", + "id": "bb2d8ee6", "metadata": { "editable": true }, @@ -5001,7 +5098,7 @@ }, { "cell_type": "markdown", - "id": "3ac39a87", + "id": "6858d622", "metadata": { "editable": true }, @@ -5011,7 +5108,7 @@ }, { "cell_type": "markdown", - "id": "e06e9fa7", + "id": "2366224e", "metadata": { "editable": true }, @@ -5023,7 +5120,7 @@ }, { "cell_type": "markdown", - "id": "cf03f73d", + "id": "31f7ea33", "metadata": { "editable": true }, @@ -5035,7 +5132,7 @@ }, { "cell_type": "markdown", - "id": "4a924f31", + "id": "b17e1d78", "metadata": { "editable": true }, @@ -5047,7 +5144,7 @@ }, { "cell_type": "markdown", - "id": "540f1997", + "id": "d52d07e2", "metadata": { "editable": true }, @@ -5059,7 +5156,7 @@ }, { "cell_type": "markdown", - "id": "cdbc9b89", + "id": "aa047574", "metadata": { "editable": true }, @@ -5071,7 +5168,7 @@ }, { "cell_type": "markdown", - "id": "452330a8", + "id": "009e010e", "metadata": { "editable": true }, @@ -5090,7 +5187,7 @@ }, { "cell_type": "markdown", - "id": "b6de3477", + "id": "ae335877", "metadata": { "editable": true }, @@ -5102,7 +5199,7 @@ }, { "cell_type": "markdown", - "id": "03f38cb5", + "id": "329ea833", "metadata": { "editable": true }, @@ -5112,7 +5209,7 @@ }, { "cell_type": "markdown", - "id": "508134a4", + "id": "ce7c1e76", "metadata": { "editable": true }, @@ -5124,7 +5221,7 @@ }, { "cell_type": "markdown", - "id": "f1a44572", + "id": "265ce6c3", "metadata": { "editable": true }, @@ -5134,7 +5231,7 @@ }, { "cell_type": "markdown", - "id": "aa80fa4c", + "id": "7a050efa", "metadata": { "editable": true }, @@ -5146,7 +5243,7 @@ }, { "cell_type": "markdown", - "id": "71fcdc4a", + "id": "03d1a51b", "metadata": { "editable": true }, @@ -5158,7 +5255,7 @@ }, { "cell_type": "markdown", - "id": "8e856380", + "id": "bc587a47", "metadata": { "editable": true }, @@ -5174,7 +5271,7 @@ }, { "cell_type": "markdown", - "id": "92df5419", + "id": "b876d6a0", "metadata": { "editable": true }, @@ -5186,7 +5283,7 @@ }, { "cell_type": "markdown", - "id": "5fbe0881", + "id": "70cb36ca", "metadata": { "editable": true }, @@ -5198,7 +5295,7 @@ }, { "cell_type": "markdown", - "id": "dd029d2e", + "id": "a708fa1c", "metadata": { "editable": true }, @@ -5208,7 +5305,7 @@ }, { "cell_type": "markdown", - "id": "75713f0f", + "id": "926faf56", "metadata": { "editable": true }, @@ -5220,7 +5317,7 @@ }, { "cell_type": "markdown", - "id": "90347f92", + "id": "fbf419a9", "metadata": { "editable": true }, @@ -5230,7 +5327,7 @@ }, { "cell_type": "markdown", - "id": "552ee48d", + "id": "b979bebf", "metadata": { "editable": true }, @@ -5242,7 +5339,7 @@ }, { "cell_type": "markdown", - "id": "7aa9e96d", + "id": "7935e6a7", "metadata": { "editable": true }, @@ -5259,7 +5356,7 @@ }, { "cell_type": "markdown", - "id": "e5a9aca9", + "id": "cdd8f913", "metadata": { "editable": true }, @@ -5271,7 +5368,7 @@ }, { "cell_type": "markdown", - "id": "ce3bfe09", + "id": "fba8ebaf", "metadata": { "editable": true }, @@ -5283,7 +5380,7 @@ }, { "cell_type": "markdown", - "id": "36158aa7", + "id": "4e8fc05c", "metadata": { "editable": true }, @@ -5293,7 +5390,7 @@ }, { "cell_type": "markdown", - "id": "189d07fb", + "id": "e5f8810b", "metadata": { "editable": true }, @@ -5305,7 +5402,7 @@ }, { "cell_type": "markdown", - "id": "f3e72532", + "id": "36005714", "metadata": { "editable": true }, @@ -5315,7 +5412,7 @@ }, { "cell_type": "markdown", - "id": "624fc00e", + "id": "75d42978", "metadata": { "editable": true }, @@ -5327,7 +5424,7 @@ }, { "cell_type": "markdown", - "id": "aa5063d5", + "id": "e56c6495", "metadata": { "editable": true }, @@ -5337,7 +5434,7 @@ }, { "cell_type": "markdown", - "id": "42a566f3", + "id": "3d8686ca", "metadata": { "editable": true }, @@ -5349,7 +5446,7 @@ }, { "cell_type": "markdown", - "id": "5d3fed6e", + "id": "9be174c4", "metadata": { "editable": true }, @@ -5359,7 +5456,7 @@ }, { "cell_type": "markdown", - "id": "05e91ccb", + "id": "eea90b23", "metadata": { "editable": true }, @@ -5371,7 +5468,7 @@ }, { "cell_type": "markdown", - "id": "b059054a", + "id": "c1476cf7", "metadata": { "editable": true }, @@ -5440,7 +5537,7 @@ }, { "cell_type": "markdown", - "id": "0bf6e778", + "id": "2edd8212", "metadata": { "editable": true }, @@ -5454,7 +5551,7 @@ { "cell_type": "code", "execution_count": 31, - "id": "3ad4858b", + "id": "6e0e205a", "metadata": { "collapsed": false, "editable": true @@ -5467,7 +5564,7 @@ }, { "cell_type": "markdown", - "id": "102dd2be", + "id": "6ed3454e", "metadata": { "editable": true }, @@ -5481,7 +5578,7 @@ }, { "cell_type": "markdown", - "id": "8b460f71", + "id": "01d370f7", "metadata": { "editable": true }, @@ -5494,7 +5591,7 @@ }, { "cell_type": "markdown", - "id": "c3217f43", + "id": "0eee5d01", "metadata": { "editable": true }, @@ -5505,7 +5602,7 @@ }, { "cell_type": "markdown", - "id": "8ee662e2", + "id": "f94c8fe5", "metadata": { "editable": true }, @@ -5517,7 +5614,7 @@ }, { "cell_type": "markdown", - "id": "43bba74a", + "id": "d65b21ce", "metadata": { "editable": true }, @@ -5527,7 +5624,7 @@ }, { "cell_type": "markdown", - "id": "e5d8e8ff", + "id": "bbdc2eff", "metadata": { "editable": true }, @@ -5539,7 +5636,7 @@ }, { "cell_type": "markdown", - "id": "a37a653d", + "id": "c7708691", "metadata": { "editable": true }, @@ -5555,7 +5652,7 @@ { "cell_type": "code", "execution_count": 32, - "id": "d616531d", + "id": "0673d3b6", "metadata": { "collapsed": false, "editable": true @@ -5606,7 +5703,7 @@ }, { "cell_type": "markdown", - "id": "6e0b8e6f", + "id": "4c4a3943", "metadata": { "editable": true }, @@ -5616,7 +5713,7 @@ }, { "cell_type": "markdown", - "id": "4d63369e", + "id": "23e98f64", "metadata": { "editable": true }, @@ -5662,7 +5759,7 @@ { "cell_type": "code", "execution_count": 33, - "id": "66c8c5a1", + "id": "1112a09b", "metadata": { "collapsed": false, "editable": true @@ -5675,7 +5772,7 @@ }, { "cell_type": "markdown", - "id": "59cb5a01", + "id": "0f8b09bd", "metadata": { "editable": true }, @@ -5686,7 +5783,7 @@ { "cell_type": "code", "execution_count": 34, - "id": "710e63a2", + "id": "15864cb4", "metadata": { "collapsed": false, "editable": true @@ -5701,7 +5798,7 @@ }, { "cell_type": "markdown", - "id": "b636233f", + "id": "747019ea", "metadata": { "editable": true }, @@ -5719,7 +5816,7 @@ { "cell_type": "code", "execution_count": 35, - "id": "678e5e7c", + "id": "605e783d", "metadata": { "collapsed": false, "editable": true @@ -5736,7 +5833,7 @@ }, { "cell_type": "markdown", - "id": "1fbf5ee7", + "id": "6d931c35", "metadata": { "editable": true }, @@ -5746,7 +5843,7 @@ }, { "cell_type": "markdown", - "id": "d7a2439b", + "id": "09a8ecc3", "metadata": { "editable": true }, @@ -5757,7 +5854,7 @@ }, { "cell_type": "markdown", - "id": "06894ac1", + "id": "d942b4b4", "metadata": { "editable": true }, @@ -5768,7 +5865,7 @@ }, { "cell_type": "markdown", - "id": "a94958ed", + "id": "146c0c64", "metadata": { "editable": true }, @@ -5779,7 +5876,7 @@ }, { "cell_type": "markdown", - "id": "215d93cd", + "id": "a92d16b0", "metadata": { "editable": true }, @@ -5802,7 +5899,7 @@ { "cell_type": "code", "execution_count": 36, - "id": "eed0bc0f", + "id": "3e35abf3", "metadata": { "collapsed": false, "editable": true @@ -5815,7 +5912,7 @@ }, { "cell_type": "markdown", - "id": "8e9867a7", + "id": "15c9d0dc", "metadata": { "editable": true }, @@ -5830,7 +5927,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "8d5faee2", + "id": "3cd74dba", "metadata": { "collapsed": false, "editable": true @@ -5910,7 +6007,7 @@ }, { "cell_type": "markdown", - "id": "45c10c0d", + "id": "07d9cf50", "metadata": { "editable": true }, @@ -5925,7 +6022,7 @@ }, { "cell_type": "markdown", - "id": "17886be0", + "id": "8a38badb", "metadata": { "editable": true }, @@ -5938,7 +6035,7 @@ }, { "cell_type": "markdown", - "id": "389b83e7", + "id": "f577916c", "metadata": { "editable": true }, @@ -5949,7 +6046,7 @@ }, { "cell_type": "markdown", - "id": "5dd35023", + "id": "98e9b66a", "metadata": { "editable": true }, @@ -5961,7 +6058,7 @@ }, { "cell_type": "markdown", - "id": "626950ab", + "id": "641131c7", "metadata": { "editable": true }, @@ -5971,7 +6068,7 @@ }, { "cell_type": "markdown", - "id": "9309f270", + "id": "f90c3422", "metadata": { "editable": true }, @@ -5983,7 +6080,7 @@ }, { "cell_type": "markdown", - "id": "730a3ff7", + "id": "c6feedc4", "metadata": { "editable": true }, @@ -5993,7 +6090,7 @@ }, { "cell_type": "markdown", - "id": "c9b656cc", + "id": "d62628ab", "metadata": { "editable": true }, @@ -6015,7 +6112,7 @@ }, { "cell_type": "markdown", - "id": "3055d266", + "id": "62d76ee9", "metadata": { "editable": true }, @@ -6027,7 +6124,7 @@ }, { "cell_type": "markdown", - "id": "4b7e0dfa", + "id": "20169a2c", "metadata": { "editable": true }, @@ -6037,7 +6134,7 @@ }, { "cell_type": "markdown", - "id": "9136efc2", + "id": "57787c09", "metadata": { "editable": true }, @@ -6049,7 +6146,7 @@ }, { "cell_type": "markdown", - "id": "24431772", + "id": "9fca015c", "metadata": { "editable": true }, @@ -6059,7 +6156,7 @@ }, { "cell_type": "markdown", - "id": "c3f86209", + "id": "3c254f35", "metadata": { "editable": true }, @@ -6071,7 +6168,7 @@ }, { "cell_type": "markdown", - "id": "fa68bb58", + "id": "046e35c2", "metadata": { "editable": true }, @@ -6084,7 +6181,7 @@ }, { "cell_type": "markdown", - "id": "9f0d1009", + "id": "41429eda", "metadata": { "editable": true }, @@ -6096,7 +6193,7 @@ }, { "cell_type": "markdown", - "id": "be855e2a", + "id": "df676985", "metadata": { "editable": true }, @@ -6106,7 +6203,7 @@ }, { "cell_type": "markdown", - "id": "85d61066", + "id": "582363b9", "metadata": { "editable": true }, @@ -6118,7 +6215,7 @@ }, { "cell_type": "markdown", - "id": "0d4df9cf", + "id": "a0db07cf", "metadata": { "editable": true }, @@ -6128,7 +6225,7 @@ }, { "cell_type": "markdown", - "id": "bf6d12a1", + "id": "cac23f34", "metadata": { "editable": true }, @@ -6140,7 +6237,7 @@ }, { "cell_type": "markdown", - "id": "58782b2d", + "id": "d424ee89", "metadata": { "editable": true }, @@ -6150,7 +6247,7 @@ }, { "cell_type": "markdown", - "id": "52d08547", + "id": "f912ccf1", "metadata": { "editable": true }, diff --git a/doc/src/week35/week35.do.txt b/doc/src/week35/week35.do.txt index 39141762a..7539ac178 100644 --- a/doc/src/week35/week35.do.txt +++ b/doc/src/week35/week35.do.txt @@ -570,6 +570,34 @@ From this we have, using the definition of the Jacobian !split ===== Example 2 ===== +We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications + +!bt +\[ +\alpha = \bm{y}^T\bm{A}\bm{x}$, +\] +!et +with $\bm{y}$ a vector of length $m$, $\bm{A}$ an $m\times n$ matrix and $\bm{x}$ a vector of length $n$. We assume also that $\bm{A}$ does not depend on any of the two vectors. +In order to find the derivative of $\alpha$ with respect to the two vectors, we define an intermediate vector $\bm{z}$. We define first +$\bm{z}^T=\bm{y}^T\bm{A}$, a vector of length $n$. We have then +!bt +\[ +\alpha = \bm{z}^T\bm{x}$, +\] +!et +which means that (using our previous example) we have +!bt +\[ +\frac{\partial \alpha}{\partial \bm{x}} = \bm{z}^T=\bm{y}^T\bm{A}. +\] +!et + +Since $\alpha$ is a scalar we have $\alpha =\alpha^T=\bm{x}^T\bm{A}^T\bm{y}$. Defining now $\bm{z}=\bm{x}^T\bm{A}^T$ we find that +!bt +\[ +\frac{\partial \alpha}{\partial \bm{y}} = \bm{z}^T=\bm{x}^T\bm{A}^T.. +\] +!et