From bd67e9417101fb857d2a005032a867ff2d67979a Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Fri, 23 Sep 2022 07:45:09 +0200 Subject: [PATCH] added more material --- doc/pub/week38/html/._week38-bs000.html | 173 +- doc/pub/week38/html/._week38-bs001.html | 173 +- doc/pub/week38/html/._week38-bs002.html | 173 +- doc/pub/week38/html/._week38-bs003.html | 173 +- doc/pub/week38/html/._week38-bs004.html | 173 +- doc/pub/week38/html/._week38-bs005.html | 173 +- doc/pub/week38/html/._week38-bs006.html | 173 +- doc/pub/week38/html/._week38-bs007.html | 173 +- doc/pub/week38/html/._week38-bs008.html | 173 +- doc/pub/week38/html/._week38-bs009.html | 173 +- doc/pub/week38/html/._week38-bs010.html | 173 +- doc/pub/week38/html/._week38-bs011.html | 173 +- doc/pub/week38/html/._week38-bs012.html | 173 +- doc/pub/week38/html/._week38-bs013.html | 173 +- doc/pub/week38/html/._week38-bs014.html | 173 +- doc/pub/week38/html/._week38-bs015.html | 173 +- doc/pub/week38/html/._week38-bs016.html | 173 +- doc/pub/week38/html/._week38-bs017.html | 173 +- doc/pub/week38/html/._week38-bs018.html | 173 +- doc/pub/week38/html/._week38-bs019.html | 173 +- doc/pub/week38/html/._week38-bs020.html | 173 +- doc/pub/week38/html/._week38-bs021.html | 173 +- doc/pub/week38/html/._week38-bs022.html | 173 +- doc/pub/week38/html/._week38-bs023.html | 173 +- doc/pub/week38/html/._week38-bs024.html | 173 +- doc/pub/week38/html/._week38-bs025.html | 173 +- doc/pub/week38/html/._week38-bs026.html | 246 +- doc/pub/week38/html/._week38-bs027.html | 258 +- doc/pub/week38/html/._week38-bs028.html | 269 +- doc/pub/week38/html/._week38-bs029.html | 200 +- doc/pub/week38/html/._week38-bs030.html | 243 +- doc/pub/week38/html/._week38-bs031.html | 252 +- doc/pub/week38/html/._week38-bs032.html | 243 +- doc/pub/week38/html/._week38-bs033.html | 202 +- doc/pub/week38/html/._week38-bs034.html | 201 +- doc/pub/week38/html/._week38-bs035.html | 208 +- doc/pub/week38/html/._week38-bs036.html | 208 +- doc/pub/week38/html/._week38-bs037.html | 236 +- doc/pub/week38/html/._week38-bs038.html | 216 +- doc/pub/week38/html/._week38-bs039.html | 207 +- doc/pub/week38/html/._week38-bs040.html | 249 +- doc/pub/week38/html/._week38-bs041.html | 211 +- doc/pub/week38/html/._week38-bs042.html | 207 +- doc/pub/week38/html/week38-bs.html | 173 +- doc/pub/week38/html/week38-reveal.html | 1415 +++++++++++ doc/pub/week38/html/week38-solarized.html | 1423 ++++++++++- doc/pub/week38/html/week38.html | 1423 ++++++++++- doc/pub/week38/ipynb/ipynb-week38-src.tar.gz | Bin 192 -> 193 bytes doc/pub/week38/ipynb/week38.ipynb | 2353 ++++++++++++++++-- doc/src/week38/week38.do.txt | 1024 ++++++++ 50 files changed, 14901 insertions(+), 1264 deletions(-) diff --git a/doc/pub/week38/html/._week38-bs000.html b/doc/pub/week38/html/._week38-bs000.html index 72a3d698d..1d4fa6b1e 100644 --- a/doc/pub/week38/html/._week38-bs000.html +++ b/doc/pub/week38/html/._week38-bs000.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -275,7 +412,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs001.html b/doc/pub/week38/html/._week38-bs001.html index 2ae737fac..166b51c71 100644 --- a/doc/pub/week38/html/._week38-bs001.html +++ b/doc/pub/week38/html/._week38-bs001.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -262,7 +399,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs002.html b/doc/pub/week38/html/._week38-bs002.html index daeea76de..476b92bfb 100644 --- a/doc/pub/week38/html/._week38-bs002.html +++ b/doc/pub/week38/html/._week38-bs002.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -303,7 +440,7 @@ $$
  • 11
  • 12
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs003.html b/doc/pub/week38/html/._week38-bs003.html index 3000e0895..07ab8f606 100644 --- a/doc/pub/week38/html/._week38-bs003.html +++ b/doc/pub/week38/html/._week38-bs003.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -268,7 +405,7 @@ cross-validation (LOOCV).
  • 12
  • 13
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs004.html b/doc/pub/week38/html/._week38-bs004.html index edb6d7631..c5c4705e2 100644 --- a/doc/pub/week38/html/._week38-bs004.html +++ b/doc/pub/week38/html/._week38-bs004.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -272,7 +409,7 @@ $$
  • 13
  • 14
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs005.html b/doc/pub/week38/html/._week38-bs005.html index 7a5e66296..89c512833 100644 --- a/doc/pub/week38/html/._week38-bs005.html +++ b/doc/pub/week38/html/._week38-bs005.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -268,7 +405,7 @@ MathJax.Hub.Config({
  • 14
  • 15
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs006.html b/doc/pub/week38/html/._week38-bs006.html index 0da959d00..db3ce49d8 100644 --- a/doc/pub/week38/html/._week38-bs006.html +++ b/doc/pub/week38/html/._week38-bs006.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -368,7 +505,7 @@ plt.show()
  • 15
  • 16
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs007.html b/doc/pub/week38/html/._week38-bs007.html index bd4fce807..76328b8cd 100644 --- a/doc/pub/week38/html/._week38-bs007.html +++ b/doc/pub/week38/html/._week38-bs007.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -269,7 +406,7 @@ simple recipe for fitting our data.
  • 16
  • 17
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs008.html b/doc/pub/week38/html/._week38-bs008.html index e623d4cb9..a23831eab 100644 --- a/doc/pub/week38/html/._week38-bs008.html +++ b/doc/pub/week38/html/._week38-bs008.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -275,7 +412,7 @@ failure etc.
  • 17
  • 18
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs009.html b/doc/pub/week38/html/._week38-bs009.html index 8923bf7e8..281c6c417 100644 --- a/doc/pub/week38/html/._week38-bs009.html +++ b/doc/pub/week38/html/._week38-bs009.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -274,7 +411,7 @@ models, as we will see later.
  • 18
  • 19
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs010.html b/doc/pub/week38/html/._week38-bs010.html index fb667c912..d4e00a28d 100644 --- a/doc/pub/week38/html/._week38-bs010.html +++ b/doc/pub/week38/html/._week38-bs010.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -282,7 +419,7 @@ $$
  • 19
  • 20
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs011.html b/doc/pub/week38/html/._week38-bs011.html index 0c9ab2836..317f3e55c 100644 --- a/doc/pub/week38/html/._week38-bs011.html +++ b/doc/pub/week38/html/._week38-bs011.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -279,7 +416,7 @@ $$
  • 20
  • 21
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs012.html b/doc/pub/week38/html/._week38-bs012.html index 5519c9c71..12e0c03a5 100644 --- a/doc/pub/week38/html/._week38-bs012.html +++ b/doc/pub/week38/html/._week38-bs012.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -279,7 +416,7 @@ the probability of a given category. This leads us to the logistic function.
  • 21
  • 22
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs013.html b/doc/pub/week38/html/._week38-bs013.html index c6009c8ff..85d62d456 100644 --- a/doc/pub/week38/html/._week38-bs013.html +++ b/doc/pub/week38/html/._week38-bs013.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -338,7 +475,7 @@ plt.show()
  • 22
  • 23
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs014.html b/doc/pub/week38/html/._week38-bs014.html index 3fcd3c8e9..33fd90952 100644 --- a/doc/pub/week38/html/._week38-bs014.html +++ b/doc/pub/week38/html/._week38-bs014.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -310,7 +447,7 @@ representing the probability for finding a value of \( y_i \) with a given
  • 23
  • 24
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs015.html b/doc/pub/week38/html/._week38-bs015.html index 55ec26504..5b97db474 100644 --- a/doc/pub/week38/html/._week38-bs015.html +++ b/doc/pub/week38/html/._week38-bs015.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -277,7 +414,7 @@ $$
  • 24
  • 25
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs016.html b/doc/pub/week38/html/._week38-bs016.html index 973dc12fe..36526f461 100644 --- a/doc/pub/week38/html/._week38-bs016.html +++ b/doc/pub/week38/html/._week38-bs016.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -338,7 +475,7 @@ plt.show()
  • 25
  • 26
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs017.html b/doc/pub/week38/html/._week38-bs017.html index 523d66dec..3b7e69ee0 100644 --- a/doc/pub/week38/html/._week38-bs017.html +++ b/doc/pub/week38/html/._week38-bs017.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -275,7 +412,7 @@ $$
  • 26
  • 27
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs018.html b/doc/pub/week38/html/._week38-bs018.html index 9e63c9a4f..eb2fcc1c8 100644 --- a/doc/pub/week38/html/._week38-bs018.html +++ b/doc/pub/week38/html/._week38-bs018.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -278,7 +415,7 @@ $$
  • 27
  • 28
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs019.html b/doc/pub/week38/html/._week38-bs019.html index ab4a754e9..af0e240bc 100644 --- a/doc/pub/week38/html/._week38-bs019.html +++ b/doc/pub/week38/html/._week38-bs019.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -275,7 +412,7 @@ in practice we often supplement the cross-entropy with additional regularization
  • 28
  • 29
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs020.html b/doc/pub/week38/html/._week38-bs020.html index c8ca0f1e6..3e59ac418 100644 --- a/doc/pub/week38/html/._week38-bs020.html +++ b/doc/pub/week38/html/._week38-bs020.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -277,7 +414,7 @@ $$
  • 29
  • 30
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs021.html b/doc/pub/week38/html/._week38-bs021.html index aeaddcc88..a0e33c5b1 100644 --- a/doc/pub/week38/html/._week38-bs021.html +++ b/doc/pub/week38/html/._week38-bs021.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -278,7 +415,7 @@ $$
  • 30
  • 31
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs022.html b/doc/pub/week38/html/._week38-bs022.html index 2183ecb3a..ab16bf58a 100644 --- a/doc/pub/week38/html/._week38-bs022.html +++ b/doc/pub/week38/html/._week38-bs022.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -270,7 +407,7 @@ $$
  • 31
  • 32
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs023.html b/doc/pub/week38/html/._week38-bs023.html index 92460bd82..0b2ecc020 100644 --- a/doc/pub/week38/html/._week38-bs023.html +++ b/doc/pub/week38/html/._week38-bs023.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -282,7 +419,7 @@ $$
  • 32
  • 33
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs024.html b/doc/pub/week38/html/._week38-bs024.html index f3d585f1f..2041362ff 100644 --- a/doc/pub/week38/html/._week38-bs024.html +++ b/doc/pub/week38/html/._week38-bs024.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -294,7 +431,7 @@ methods.
  • 33
  • 34
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs025.html b/doc/pub/week38/html/._week38-bs025.html index a8acf9929..da2831244 100644 --- a/doc/pub/week38/html/._week38-bs025.html +++ b/doc/pub/week38/html/._week38-bs025.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -259,7 +396,7 @@ MathJax.Hub.Config({
  • 34
  • 35
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs026.html b/doc/pub/week38/html/._week38-bs026.html index a1ad018a3..eaa46c944 100644 --- a/doc/pub/week38/html/._week38-bs026.html +++ b/doc/pub/week38/html/._week38-bs026.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,36 +369,67 @@ MathJax.Hub.Config({

     

     

     

    -

    Wisconsin Cancer Data

    +

    Searching for Optimal Regularization Parameters \( \lambda \)

    -

    We show here how we can use a simple regression case on the breast -cancer data using Logistic regression as our algorithm for -classification. +

    In project 1, when using Ridge and Lasso regression, we end up +searching for the optimal parameter \( \lambda \) which minimizes our +selected scores (MSE or \( R2 \) values for example). The brute force +approach, as discussed in the code here for Ridge regression, consists +in evaluating the MSE as function of different \( \lambda \) values. +Based on these calculations, one tries then to determine the value of the hyperparameter \( \lambda \) +which results in optimal scores (for example the smallest MSE or an \( R2=1 \)).

    -
    -
    import matplotlib.pyplot as plt
    -import numpy as np
    -from sklearn.model_selection import  train_test_split 
    -from sklearn.datasets import load_breast_cancer
    -from sklearn.linear_model import LogisticRegression
    +  
    import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
     
    -# Load the data
    -cancer = load_breast_cancer()
    +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(2021)
     
    -X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
    -print(X_train.shape)
    -print(X_test.shape)
    -# Logistic Regression
    -logreg = LogisticRegression(solver='lbfgs')
    -logreg.fit(X_train, y_train)
    -print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 500
    +MSERidgePredict = np.zeros(nlambdas)
    +lambdas = np.logspace(-4, 2, nlambdas)
    +for i in range(nlambdas):
    +    lmb = lambdas[i]
    +    RegRidge = linear_model.Ridge(lmb)
    +    RegRidge.fit(X_train,y_train)
    +    ypredictRidge = RegRidge.predict(X_test)
    +    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    +
    +# Now plot the results
    +plt.figure()
    +plt.plot(np.log10(lambdas), MSERidgePredict, 'g--', label = 'MSE SL Ridge Test')
    +plt.xlabel('log10(lambda)')
    +plt.ylabel('MSE')
    +plt.legend()
    +plt.show()
     
    @@ -277,6 +445,10 @@ logreg.fit(X_train, y_train)
    +

    Here we have performed a rather data greedy calculation as function of the regularization parameter \( \lambda \). There is no resampling here. The latter can easily be added by employing the function RidgeCV instead of just calling the Ridge function. For RidgeCV we need to pass the array of \( \lambda \) values. +By inspecting the figure we can in turn determine which is the optimal regularization parameter. +This becomes however less functional in the long run. +

    @@ -303,7 +475,7 @@ logreg.fit(X_train, y_train)

  • 35
  • 36
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs027.html b/doc/pub/week38/html/._week38-bs027.html index bb5becf55..877e64c68 100644 --- a/doc/pub/week38/html/._week38-bs027.html +++ b/doc/pub/week38/html/._week38-bs027.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,52 +369,62 @@ MathJax.Hub.Config({

     

     

     

    -

    Using the correlation matrix

    + -

    In addition to the above scores, we could also study the covariance (and the correlation matrix). -We use Pandas to compute the correlation matrix. +

    An alternative is to use the so-called grid search functionality +included with the library Scikit-Learn, as demonstrated for the same +example here.

    +
    -
    import matplotlib.pyplot as plt
    -import numpy as np
    -from sklearn.model_selection import  train_test_split 
    -from sklearn.datasets import load_breast_cancer
    -from sklearn.linear_model import LogisticRegression
    -cancer = load_breast_cancer()
    -import pandas as pd
    -# Making a data frame
    -cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
    +  
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
     
    -fig, axes = plt.subplots(15,2,figsize=(10,20))
    -malignant = cancer.data[cancer.target == 0]
    -benign = cancer.data[cancer.target == 1]
    -ax = axes.ravel()
    +def R2(y_data, y_model):
    +    return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
     
    -for i in range(30):
    -    _, bins = np.histogram(cancer.data[:,i], bins =50)
    -    ax[i].hist(malignant[:,i], bins = bins, alpha = 0.5)
    -    ax[i].hist(benign[:,i], bins = bins, alpha = 0.5)
    -    ax[i].set_title(cancer.feature_names[i])
    -    ax[i].set_yticks(())
    -ax[0].set_xlabel("Feature magnitude")
    -ax[0].set_ylabel("Frequency")
    -ax[0].legend(["Malignant", "Benign"], loc ="best")
    -fig.tight_layout()
    -plt.show()
    +def MSE(y_data,y_model):
    +    n = np.size(y_model)
    +    return np.sum((y_data-y_model)**2)/n
     
    -import seaborn as sns
    -correlation_matrix = cancerpd.corr().round(1)
    -# use the heatmap function from seaborn to plot the correlation matrix
    -# annot = True to print the values inside the square
    -plt.figure(figsize=(15,8))
    -sns.heatmap(data=correlation_matrix, annot=True)
    -plt.show()
    +# A seed just to ensure that the random numbers are the same for every run.
    +# Useful for eventual debugging.
    +np.random.seed(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 10
    +lambdas = np.logspace(-4, 2, nlambdas)
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
     
    @@ -293,6 +440,13 @@ plt.show()
    +

    By default the grid search function includes cross validation with +five folds. The Scikit-Learn +documentation +contains more information on how to set the different parameters. +

    + +

    If we take out the random noise, running the above codes results in \( \lambda=0 \) yielding the best fit.

    @@ -319,7 +473,7 @@ plt.show()

  • 36
  • 37
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs028.html b/doc/pub/week38/html/._week38-bs028.html index ac98b8d96..33cd7da8d 100644 --- a/doc/pub/week38/html/._week38-bs028.html +++ b/doc/pub/week38/html/._week38-bs028.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,23 +369,18 @@ MathJax.Hub.Config({

     

     

     

    -

    Discussing the correlation data

    + -

    In the above example we note two things. In the first plot we display -the overlap of benign and malignant tumors as functions of the various -features in the Wisconsing breast cancer data set. We see that for -some of the features we can distinguish clearly the benign and -malignant cases while for other features we cannot. This can point to -us which features may be of greater interest when we wish to classify -a benign or not benign tumour. +

    An alternative to the above manual grid set up, is to use a random +search where the parameters are tuned from a random distribution +(uniform below) for a fixed number of iterations. A model is +constructed and evaluated for each combination of chosen parameters. +We repeat the previous example but now with a random search. Note +that values of \( \lambda \) are now limited to be within \( x\in +[0,1] \). This domain may not be the most relevant one for the specific +case under study.

    -

    In the second figure we have computed the so-called correlation -matrix, which in our case with thirty features becomes a \( 30\times 30 \) -matrix. -

    - -

    We constructed this matrix using pandas via the statements

    @@ -256,7 +388,49 @@ matrix.
    -
    cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
    +  
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +from scipy.stats import uniform as randuniform
    +from sklearn.model_selection import RandomizedSearchCV
    +
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +param_grid = {'alpha': randuniform()}
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
     
    @@ -272,35 +446,6 @@ matrix.
    -

    and then

    - - -
    -
    -
    -
    -
    -
    correlation_matrix = cancerpd.corr().round(1)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Diagonalizing this matrix we can in turn say something about which -features are of relevance and which are not. This leads us to -the classical Principal Component Analysis (PCA) theorem with -applications. This will be discussed later this semester (week 43). -

    @@ -327,7 +472,7 @@ applications. This will be discussed later this semester (37

  • 38
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs029.html b/doc/pub/week38/html/._week38-bs029.html index f2011227c..4c6444577 100644 --- a/doc/pub/week38/html/._week38-bs029.html +++ b/doc/pub/week38/html/._week38-bs029.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,7 +369,13 @@ MathJax.Hub.Config({

     

     

     

    -

    Other measures in classification studies: Cancer Data again

    +

    Wisconsin Cancer Data

    + +

    We show here how we can use a simple regression case on the breast +cancer data using Logistic regression as our algorithm for +classification. +

    +
    @@ -256,25 +399,6 @@ X_train, X_test, y_train, y_test = train_tes logreg = LogisticRegression(solver='lbfgs') logreg.fit(X_train, y_train) print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) - - -from sklearn.preprocessing import LabelEncoder -from sklearn.model_selection import cross_validate -#Cross validation -accuracy = cross_validate(logreg,X_test,y_test,cv=10)['test_score'] -print(accuracy) -print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) - - -import scikitplot as skplt -y_pred = logreg.predict(X_test) -skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) -plt.show() -y_probas = logreg.predict_proba(X_test) -skplt.metrics.plot_roc(y_test, y_probas) -plt.show() -skplt.metrics.plot_cumulative_gain(y_test, y_probas) -plt.show()
    @@ -316,7 +440,7 @@ plt.show()
  • 38
  • 39
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs030.html b/doc/pub/week38/html/._week38-bs030.html index 5751878b5..ae88f38af 100644 --- a/doc/pub/week38/html/._week38-bs030.html +++ b/doc/pub/week38/html/._week38-bs030.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,20 +369,68 @@ MathJax.Hub.Config({

     

     

     

    -

    Optimization, the central part of any Machine Learning algortithm

    +

    Using the correlation matrix

    -Overview Video, why do we care about gradient methods? - -

    Almost every problem in machine learning and data science starts with -a dataset \( X \), a model \( g(\beta) \), which is a function of the -parameters \( \beta \) and a cost function \( C(X, g(\beta)) \) that allows -us to judge how well the model \( g(\beta) \) explains the observations -\( X \). The model is fit by finding the values of \( \beta \) that minimize -the cost function. Ideally we would be able to solve for \( \beta \) -analytically, however this is not possible in general and we must use -some approximative/numerical method to compute the minimum. +

    In addition to the above scores, we could also study the covariance (and the correlation matrix). +We use Pandas to compute the correlation matrix.

    + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
    +from sklearn.linear_model import LogisticRegression
    +cancer = load_breast_cancer()
    +import pandas as pd
    +# Making a data frame
    +cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
    +
    +fig, axes = plt.subplots(15,2,figsize=(10,20))
    +malignant = cancer.data[cancer.target == 0]
    +benign = cancer.data[cancer.target == 1]
    +ax = axes.ravel()
    +
    +for i in range(30):
    +    _, bins = np.histogram(cancer.data[:,i], bins =50)
    +    ax[i].hist(malignant[:,i], bins = bins, alpha = 0.5)
    +    ax[i].hist(benign[:,i], bins = bins, alpha = 0.5)
    +    ax[i].set_title(cancer.feature_names[i])
    +    ax[i].set_yticks(())
    +ax[0].set_xlabel("Feature magnitude")
    +ax[0].set_ylabel("Frequency")
    +ax[0].legend(["Malignant", "Benign"], loc ="best")
    +fig.tight_layout()
    +plt.show()
    +
    +import seaborn as sns
    +correlation_matrix = cancerpd.corr().round(1)
    +# use the heatmap function from seaborn to plot the correlation matrix
    +# annot = True to print the values inside the square
    +plt.figure(figsize=(15,8))
    +sns.heatmap(data=correlation_matrix, annot=True)
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    diff --git a/doc/pub/week38/html/._week38-bs031.html b/doc/pub/week38/html/._week38-bs031.html index be0290b7f..930b97ef0 100644 --- a/doc/pub/week38/html/._week38-bs031.html +++ b/doc/pub/week38/html/._week38-bs031.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,24 +369,75 @@ MathJax.Hub.Config({

     

     

     

    -

    Revisiting our Logistic Regression case

    +

    Discussing the correlation data

    -

    In our discussion on Logistic Regression we studied the -case of -two classes, with \( y_i \) either -\( 0 \) or \( 1 \). Furthermore we assumed also that we have only two -parameters \( \beta \) in our fitting, that is we -defined probabilities +

    In the above example we note two things. In the first plot we display +the overlap of benign and malignant tumors as functions of the various +features in the Wisconsing breast cancer data set. We see that for +some of the features we can distinguish clearly the benign and +malignant cases while for other features we cannot. This can point to +us which features may be of greater interest when we wish to classify +a benign or not benign tumour.

    -$$ -\begin{align*} -p(y_i=1|x_i,\boldsymbol{\beta}) &= \frac{\exp{(\beta_0+\beta_1x_i)}}{1+\exp{(\beta_0+\beta_1x_i)}},\nonumber\\ -p(y_i=0|x_i,\boldsymbol{\beta}) &= 1 - p(y_i=1|x_i,\boldsymbol{\beta}), -\end{align*} -$$ +

    In the second figure we have computed the so-called correlation +matrix, which in our case with thirty features becomes a \( 30\times 30 \) +matrix. +

    -

    where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in our case \( \beta_0 \) and \( \beta_1 \).

    +

    We constructed this matrix using pandas via the statements

    + + +
    +
    +
    +
    +
    +
    cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    and then

    + + +
    +
    +
    +
    +
    +
    correlation_matrix = cancerpd.corr().round(1)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Diagonalizing this matrix we can in turn say something about which +features are of relevance and which are not. This leads us to +the classical Principal Component Analysis (PCA) theorem with +applications. This will be discussed later this semester (week 43). +

    @@ -276,7 +464,7 @@ $$

  • 40
  • 41
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs032.html b/doc/pub/week38/html/._week38-bs032.html index 8df35c3c3..ac5785479 100644 --- a/doc/pub/week38/html/._week38-bs032.html +++ b/doc/pub/week38/html/._week38-bs032.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,28 +369,64 @@ MathJax.Hub.Config({

     

     

     

    -

    The equations to solve

    +

    Other measures in classification studies: Cancer Data again

    -

    Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \) -elements \( y_i \), an \( n\times p \) matrix \( \boldsymbol{X} \) which contains the -\( x_i \) values and a vector \( \boldsymbol{p} \) of fitted probabilities -\( p(y_i\vert x_i,\boldsymbol{\beta}) \). We rewrote in a more compact form -the first derivative of the cost function as -

    + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
    +from sklearn.linear_model import LogisticRegression
     
    -$$
    -\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{p}\right). 
    -$$
    +# Load the data
    +cancer = load_breast_cancer()
     
    -

    If we in addition define a diagonal matrix \( \boldsymbol{W} \) with elements -\( p(y_i\vert x_i,\boldsymbol{\beta})(1-p(y_i\vert x_i,\boldsymbol{\beta}) \), we can obtain a compact expression of the second derivative as -

    +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) +print(X_train.shape) +print(X_test.shape) +# Logistic Regression +logreg = LogisticRegression(solver='lbfgs') +logreg.fit(X_train, y_train) +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) -$$ -\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T} = \boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X}. -$$ -

    This defines what is called the Hessian matrix.

    +from sklearn.preprocessing import LabelEncoder +from sklearn.model_selection import cross_validate +#Cross validation +accuracy = cross_validate(logreg,X_test,y_test,cv=10)['test_score'] +print(accuracy) +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) + + +import scikitplot as skplt +y_pred = logreg.predict(X_test) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = logreg.predict_proba(X_test) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) +plt.show() +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -279,6 +452,8 @@ $$

  • 40
  • 41
  • 42
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs033.html b/doc/pub/week38/html/._week38-bs033.html index c4184c30b..d9670a65e 100644 --- a/doc/pub/week38/html/._week38-bs033.html +++ b/doc/pub/week38/html/._week38-bs033.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,25 +369,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Solving using Newton-Raphson's method

    +

    Optimization, the central part of any Machine Learning algortithm

    -

    If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.

    +Overview Video, why do we care about gradient methods? -

    Our iterative scheme is then given by

    - -$$ -\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T}\right)^{-1}_{\boldsymbol{\beta}^{\mathrm{old}}}\times \left(\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}\right)_{\boldsymbol{\beta}^{\mathrm{old}}}, -$$ - -

    or in matrix form as

    - -$$ -\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X} \right)^{-1}\times \left(-\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{p}) \right)_{\boldsymbol{\beta}^{\mathrm{old}}}. -$$ - -

    The right-hand side is computed with the old values of \( \beta \).

    - -

    If we can compute these matrices, in particular the Hessian, the above is often the easiest method to implement.

    +

    Almost every problem in machine learning and data science starts with +a dataset \( X \), a model \( g(\beta) \), which is a function of the +parameters \( \beta \) and a cost function \( C(X, g(\beta)) \) that allows +us to judge how well the model \( g(\beta) \) explains the observations +\( X \). The model is fit by finding the values of \( \beta \) that minimize +the cost function. Ideally we would be able to solve for \( \beta \) +analytically, however this is not possible in general and we must use +some approximative/numerical method to compute the minimum. +

    @@ -275,6 +406,9 @@ $$

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs034.html b/doc/pub/week38/html/._week38-bs034.html index b223ec106..bbd9bbf63 100644 --- a/doc/pub/week38/html/._week38-bs034.html +++ b/doc/pub/week38/html/._week38-bs034.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,19 +369,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Brief reminder on Newton-Raphson's method

    +

    Revisiting our Logistic Regression case

    -

    Let us quickly remind ourselves how we derive the above method.

    - -

    Perhaps the most celebrated of all one-dimensional root-finding -routines is Newton's method, also called the Newton-Raphson -method. This method requires the evaluation of both the -function \( f \) and its derivative \( f' \) at arbitrary points. -If you can only calculate the derivative -numerically and/or your function is not of the smooth type, we -normally discourage the use of this method. +

    In our discussion on Logistic Regression we studied the +case of +two classes, with \( y_i \) either +\( 0 \) or \( 1 \). Furthermore we assumed also that we have only two +parameters \( \beta \) in our fitting, that is we +defined probabilities

    +$$ +\begin{align*} +p(y_i=1|x_i,\boldsymbol{\beta}) &= \frac{\exp{(\beta_0+\beta_1x_i)}}{1+\exp{(\beta_0+\beta_1x_i)}},\nonumber\\ +p(y_i=0|x_i,\boldsymbol{\beta}) &= 1 - p(y_i=1|x_i,\boldsymbol{\beta}), +\end{align*} +$$ + +

    where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in our case \( \beta_0 \) and \( \beta_1 \).

    +

    diff --git a/doc/pub/week38/html/._week38-bs035.html b/doc/pub/week38/html/._week38-bs035.html index d2b29e53a..e2e480e56 100644 --- a/doc/pub/week38/html/._week38-bs035.html +++ b/doc/pub/week38/html/._week38-bs035.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,38 +369,28 @@ MathJax.Hub.Config({

     

     

     

    -

    The equations

    +

    The equations to solve

    -

    The Newton-Raphson formula consists geometrically of extending the -tangent line at a current point until it crosses zero, then setting -the next guess to the abscissa of that zero-crossing. The mathematics -behind this method is rather simple. Employing a Taylor expansion for -\( x \) sufficiently close to the solution \( s \), we have +

    Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \) +elements \( y_i \), an \( n\times p \) matrix \( \boldsymbol{X} \) which contains the +\( x_i \) values and a vector \( \boldsymbol{p} \) of fitted probabilities +\( p(y_i\vert x_i,\boldsymbol{\beta}) \). We rewrote in a more compact form +the first derivative of the cost function as

    $$ - f(s)=0=f(x)+(s-x)f'(x)+\frac{(s-x)^2}{2}f''(x) +\dots. - \tag{2} +\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{p}\right). $$ -

    For small enough values of the function and for well-behaved -functions, the terms beyond linear are unimportant, hence we obtain +

    If we in addition define a diagonal matrix \( \boldsymbol{W} \) with elements +\( p(y_i\vert x_i,\boldsymbol{\beta})(1-p(y_i\vert x_i,\boldsymbol{\beta}) \), we can obtain a compact expression of the second derivative as

    $$ - f(x)+(s-x)f'(x)\approx 0, -$$ - -

    yielding

    -$$ - s\approx x-\frac{f(x)}{f'(x)}. -$$ - -

    Having in mind an iterative procedure, it is natural to start iterating with

    -$$ - x_{n+1}=x_n-\frac{f(x_n)}{f'(x_n)}. +\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T} = \boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X}. $$ +

    This defines what is called the Hessian matrix.

    @@ -286,6 +413,11 @@ $$

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs036.html b/doc/pub/week38/html/._week38-bs036.html index 34dedcd05..0e1963998 100644 --- a/doc/pub/week38/html/._week38-bs036.html +++ b/doc/pub/week38/html/._week38-bs036.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,20 +369,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Simple geometric interpretation

    +

    Solving using Newton-Raphson's method

    -

    The above is Newton-Raphson's method. It has a simple geometric -interpretation, namely \( x_{n+1} \) is the point where the tangent from -\( (x_n,f(x_n)) \) crosses the \( x \)-axis. Close to the solution, -Newton-Raphson converges fast to the desired result. However, if we -are far from a root, where the higher-order terms in the series are -important, the Newton-Raphson formula can give grossly inaccurate -results. For instance, the initial guess for the root might be so far -from the true root as to let the search interval include a local -maximum or minimum of the function. If an iteration places a trial -guess near such a local extremum, so that the first derivative nearly -vanishes, then Newton-Raphson may fail totally -

    +

    If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.

    + +

    Our iterative scheme is then given by

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T}\right)^{-1}_{\boldsymbol{\beta}^{\mathrm{old}}}\times \left(\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}\right)_{\boldsymbol{\beta}^{\mathrm{old}}}, +$$ + +

    or in matrix form as

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X} \right)^{-1}\times \left(-\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{p}) \right)_{\boldsymbol{\beta}^{\mathrm{old}}}. +$$ + +

    The right-hand side is computed with the old values of \( \beta \).

    + +

    If we can compute these matrices, in particular the Hessian, the above is often the easiest method to implement.

    @@ -267,6 +409,12 @@ vanishes, then Newton-Raphson may fail totally

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs037.html b/doc/pub/week38/html/._week38-bs037.html index dbbd9e692..c8ceb83ec 100644 --- a/doc/pub/week38/html/._week38-bs037.html +++ b/doc/pub/week38/html/._week38-bs037.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,57 +369,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Extending to more than one variable

    +

    Brief reminder on Newton-Raphson's method

    -

    Newton's method can be generalized to systems of several non-linear equations -and variables. Consider the case with two equations -

    -$$ - \begin{array}{cc} f_1(x_1,x_2) &=0\\ - f_2(x_1,x_2) &=0,\end{array} -$$ +

    Let us quickly remind ourselves how we derive the above method.

    -

    which we Taylor expand to obtain

    - -$$ - \begin{array}{cc} 0=f_1(x_1+h_1,x_2+h_2)=&f_1(x_1,x_2)+h_1 - \partial f_1/\partial x_1+h_2 - \partial f_1/\partial x_2+\dots\\ - 0=f_2(x_1+h_1,x_2+h_2)=&f_2(x_1,x_2)+h_1 - \partial f_2/\partial x_1+h_2 - \partial f_2/\partial x_2+\dots - \end{array}. -$$ - -

    Defining the Jacobian matrix \( {\bf \boldsymbol{J}} \) we have

    -$$ - {\bf \boldsymbol{J}}=\left( \begin{array}{cc} - \partial f_1/\partial x_1 & \partial f_1/\partial x_2 \\ - \partial f_2/\partial x_1 &\partial f_2/\partial x_2 - \end{array} \right), -$$ - -

    we can rephrase Newton's method as

    -$$ -\left(\begin{array}{c} x_1^{n+1} \\ x_2^{n+1} \end{array} \right)= -\left(\begin{array}{c} x_1^{n} \\ x_2^{n} \end{array} \right)+ -\left(\begin{array}{c} h_1^{n} \\ h_2^{n} \end{array} \right), -$$ - -

    where we have defined

    -$$ - \left(\begin{array}{c} h_1^{n} \\ h_2^{n} \end{array} \right)= - -{\bf \boldsymbol{J}}^{-1} - \left(\begin{array}{c} f_1(x_1^{n},x_2^{n}) \\ f_2(x_1^{n},x_2^{n}) \end{array} \right). -$$ - -

    We need thus to compute the inverse of the Jacobian matrix and it -is to understand that difficulties may -arise in case \( {\bf \boldsymbol{J}} \) is nearly singular. -

    - -

    It is rather straightforward to extend the above scheme to systems of -more than two non-linear equations. In our case, the Jacobian matrix is given by the Hessian that represents the second derivative of cost function. +

    Perhaps the most celebrated of all one-dimensional root-finding +routines is Newton's method, also called the Newton-Raphson +method. This method requires the evaluation of both the +function \( f \) and its derivative \( f' \) at arbitrary points. +If you can only calculate the derivative +numerically and/or your function is not of the smooth type, we +normally discourage the use of this method.

    @@ -304,6 +401,13 @@ more than two non-linear equations. In our case, the Jacobian matrix is given by

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • 47
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs038.html b/doc/pub/week38/html/._week38-bs038.html index f1bdd342c..ab3d827b2 100644 --- a/doc/pub/week38/html/._week38-bs038.html +++ b/doc/pub/week38/html/._week38-bs038.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -232,26 +369,39 @@ MathJax.Hub.Config({

     

     

     

    -

    Steepest descent

    +

    The equations

    -

    The basic idea of gradient descent is -that a function \( F(\mathbf{x}) \), -\( \mathbf{x} \equiv (x_1,\cdots,x_n) \), decreases fastest if one goes from \( \bf {x} \) in the -direction of the negative gradient \( -\nabla F(\mathbf{x}) \). +

    The Newton-Raphson formula consists geometrically of extending the +tangent line at a current point until it crosses zero, then setting +the next guess to the abscissa of that zero-crossing. The mathematics +behind this method is rather simple. Employing a Taylor expansion for +\( x \) sufficiently close to the solution \( s \), we have

    -

    It can be shown that if

    $$ -\mathbf{x}_{k+1} = \mathbf{x}_k - \gamma_k \nabla F(\mathbf{x}_k), + f(s)=0=f(x)+(s-x)f'(x)+\frac{(s-x)^2}{2}f''(x) +\dots. + \tag{2} $$ -

    with \( \gamma_k > 0 \).

    - -

    For \( \gamma_k \) small enough, then \( F(\mathbf{x}_{k+1}) \leq -F(\mathbf{x}_k) \). This means that for a sufficiently small \( \gamma_k \) -we are always moving towards smaller function values, i.e a minimum. +

    For small enough values of the function and for well-behaved +functions, the terms beyond linear are unimportant, hence we obtain

    +$$ + f(x)+(s-x)f'(x)\approx 0, +$$ + +

    yielding

    +$$ + s\approx x-\frac{f(x)}{f'(x)}. +$$ + +

    Having in mind an iterative procedure, it is natural to start iterating with

    +$$ + x_{n+1}=x_n-\frac{f(x_n)}{f'(x_n)}. +$$ + +

    diff --git a/doc/pub/week38/html/._week38-bs039.html b/doc/pub/week38/html/._week38-bs039.html index 837d6c637..6c76038c7 100644 --- a/doc/pub/week38/html/._week38-bs039.html +++ b/doc/pub/week38/html/._week38-bs039.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -231,21 +368,20 @@ MathJax.Hub.Config({

     

     

     

    - -

    More on Steepest descent

    + +

    Simple geometric interpretation

    -

    The previous observation is the basis of the method of steepest -descent, which is also referred to as just gradient descent (GD). One -starts with an initial guess \( \mathbf{x}_0 \) for a minimum of \( F \) and -computes new approximations according to -

    - -$$ -\mathbf{x}_{k+1} = \mathbf{x}_k - \gamma_k \nabla F(\mathbf{x}_k), \ \ k \geq 0. -$$ - -

    The parameter \( \gamma_k \) is often referred to as the step length or -the learning rate within the context of Machine Learning. +

    The above is Newton-Raphson's method. It has a simple geometric +interpretation, namely \( x_{n+1} \) is the point where the tangent from +\( (x_n,f(x_n)) \) crosses the \( x \)-axis. Close to the solution, +Newton-Raphson converges fast to the desired result. However, if we +are far from a root, where the higher-order terms in the series are +important, the Newton-Raphson formula can give grossly inaccurate +results. For instance, the initial guess for the root might be so far +from the true root as to let the search interval include a local +maximum or minimum of the function. If an iteration places a trial +guess near such a local extremum, so that the first derivative nearly +vanishes, then Newton-Raphson may fail totally

    @@ -265,6 +401,15 @@ the learning rate within the context of Machine Learning.

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • 47
  • +
  • 48
  • +
  • 49
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs040.html b/doc/pub/week38/html/._week38-bs040.html index 53207ded4..07a636bb9 100644 --- a/doc/pub/week38/html/._week38-bs040.html +++ b/doc/pub/week38/html/._week38-bs040.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -231,28 +368,58 @@ MathJax.Hub.Config({

     

     

     

    - -

    The ideal

    + +

    Extending to more than one variable

    -

    Ideally the sequence \( \{\mathbf{x}_k \}_{k=0} \) converges to a global -minimum of the function \( F \). In general we do not know if we are in a -global or local minimum. In the special case when \( F \) is a convex -function, all local minima are also global minima, so in this case -gradient descent can converge to the global solution. The advantage of -this scheme is that it is conceptually simple and straightforward to -implement. However the method in this form has some severe -limitations: +

    Newton's method can be generalized to systems of several non-linear equations +and variables. Consider the case with two equations +

    +$$ + \begin{array}{cc} f_1(x_1,x_2) &=0\\ + f_2(x_1,x_2) &=0,\end{array} +$$ + +

    which we Taylor expand to obtain

    + +$$ + \begin{array}{cc} 0=f_1(x_1+h_1,x_2+h_2)=&f_1(x_1,x_2)+h_1 + \partial f_1/\partial x_1+h_2 + \partial f_1/\partial x_2+\dots\\ + 0=f_2(x_1+h_1,x_2+h_2)=&f_2(x_1,x_2)+h_1 + \partial f_2/\partial x_1+h_2 + \partial f_2/\partial x_2+\dots + \end{array}. +$$ + +

    Defining the Jacobian matrix \( {\bf \boldsymbol{J}} \) we have

    +$$ + {\bf \boldsymbol{J}}=\left( \begin{array}{cc} + \partial f_1/\partial x_1 & \partial f_1/\partial x_2 \\ + \partial f_2/\partial x_1 &\partial f_2/\partial x_2 + \end{array} \right), +$$ + +

    we can rephrase Newton's method as

    +$$ +\left(\begin{array}{c} x_1^{n+1} \\ x_2^{n+1} \end{array} \right)= +\left(\begin{array}{c} x_1^{n} \\ x_2^{n} \end{array} \right)+ +\left(\begin{array}{c} h_1^{n} \\ h_2^{n} \end{array} \right), +$$ + +

    where we have defined

    +$$ + \left(\begin{array}{c} h_1^{n} \\ h_2^{n} \end{array} \right)= + -{\bf \boldsymbol{J}}^{-1} + \left(\begin{array}{c} f_1(x_1^{n},x_2^{n}) \\ f_2(x_1^{n},x_2^{n}) \end{array} \right). +$$ + +

    We need thus to compute the inverse of the Jacobian matrix and it +is to understand that difficulties may +arise in case \( {\bf \boldsymbol{J}} \) is nearly singular.

    -

    In machine learing we are often faced with non-convex high dimensional -cost functions with many local minima. Since GD is deterministic we -will get stuck in a local minimum, if the method converges, unless we -have a very good intial guess. This also implies that the scheme is -sensitive to the chosen initial condition. -

    - -

    Note that the gradient is a function of \( \mathbf{x} = -(x_1,\cdots,x_n) \) which makes it expensive to compute numerically. +

    It is rather straightforward to extend the above scheme to systems of +more than two non-linear equations. In our case, the Jacobian matrix is given by the Hessian that represents the second derivative of cost function.

    @@ -271,6 +438,16 @@ sensitive to the chosen initial condition.

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • 47
  • +
  • 48
  • +
  • 49
  • +
  • 50
  • +
  • ...
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs041.html b/doc/pub/week38/html/._week38-bs041.html index b4098c011..c83916e06 100644 --- a/doc/pub/week38/html/._week38-bs041.html +++ b/doc/pub/week38/html/._week38-bs041.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -231,21 +368,25 @@ MathJax.Hub.Config({

     

     

     

    - -

    The sensitiveness of the gradient descent

    + +

    Steepest descent

    -

    The gradient descent method -is sensitive to the choice of learning rate \( \gamma_k \). This is due -to the fact that we are only guaranteed that \( F(\mathbf{x}_{k+1}) \leq -F(\mathbf{x}_k) \) for sufficiently small \( \gamma_k \). The problem is to -determine an optimal learning rate. If the learning rate is chosen too -small the method will take a long time to converge and if it is too -large we can experience erratic behavior. +

    The basic idea of gradient descent is +that a function \( F(\mathbf{x}) \), +\( \mathbf{x} \equiv (x_1,\cdots,x_n) \), decreases fastest if one goes from \( \bf {x} \) in the +direction of the negative gradient \( -\nabla F(\mathbf{x}) \).

    -

    Many of these shortcomings can be alleviated by introducing -randomness. One such method is that of Stochastic Gradient Descent -(SGD), see below. +

    It can be shown that if

    +$$ +\mathbf{x}_{k+1} = \mathbf{x}_k - \gamma_k \nabla F(\mathbf{x}_k), +$$ + +

    with \( \gamma_k > 0 \).

    + +

    For \( \gamma_k \) small enough, then \( F(\mathbf{x}_{k+1}) \leq +F(\mathbf{x}_k) \). This means that for a sufficiently small \( \gamma_k \) +we are always moving towards smaller function values, i.e a minimum.

    @@ -263,6 +404,18 @@ randomness. One such method is that of Stochastic Gradient Descent

  • 40
  • 41
  • 42
  • +
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • 47
  • +
  • 48
  • +
  • 49
  • +
  • 50
  • +
  • 51
  • +
  • ...
  • +
  • 79
  • +
  • »
  • diff --git a/doc/pub/week38/html/._week38-bs042.html b/doc/pub/week38/html/._week38-bs042.html index f566e96b7..f67b4f5e6 100644 --- a/doc/pub/week38/html/._week38-bs042.html +++ b/doc/pub/week38/html/._week38-bs042.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -112,7 +118,6 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'other-measures-in-classification-studies-cancer-data-again'), - ('Friday September 25', 2, None, 'friday-september-25'), ('Optimization, the central part of any Machine Learning ' 'algortithm', 2, @@ -146,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -206,23 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Friday September 25
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -234,20 +369,20 @@ MathJax.Hub.Config({

     

     

     

    -

    The sensitiveness of the gradient descent

    +

    More on Steepest descent

    -

    The gradient descent method -is sensitive to the choice of learning rate \( \gamma_k \). This is due -to the fact that we are only guaranteed that \( F(\mathbf{x}_{k+1}) \leq -F(\mathbf{x}_k) \) for sufficiently small \( \gamma_k \). The problem is to -determine an optimal learning rate. If the learning rate is chosen too -small the method will take a long time to converge and if it is too -large we can experience erratic behavior. +

    The previous observation is the basis of the method of steepest +descent, which is also referred to as just gradient descent (GD). One +starts with an initial guess \( \mathbf{x}_0 \) for a minimum of \( F \) and +computes new approximations according to

    -

    Many of these shortcomings can be alleviated by introducing -randomness. One such method is that of Stochastic Gradient Descent -(SGD), see below. +$$ +\mathbf{x}_{k+1} = \mathbf{x}_k - \gamma_k \nabla F(\mathbf{x}_k), \ \ k \geq 0. +$$ + +

    The parameter \( \gamma_k \) is often referred to as the step length or +the learning rate within the context of Machine Learning.

    @@ -265,6 +400,18 @@ randomness. One such method is that of Stochastic Gradient Descent

  • 41
  • 42
  • 43
  • +
  • 44
  • +
  • 45
  • +
  • 46
  • +
  • 47
  • +
  • 48
  • +
  • 49
  • +
  • 50
  • +
  • 51
  • +
  • 52
  • +
  • ...
  • +
  • 79
  • +
  • »
  • diff --git a/doc/pub/week38/html/week38-bs.html b/doc/pub/week38/html/week38-bs.html index 72a3d698d..1d4fa6b1e 100644 --- a/doc/pub/week38/html/week38-bs.html +++ b/doc/pub/week38/html/week38-bs.html @@ -99,6 +99,12 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -145,7 +151,101 @@ doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=d ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -205,22 +305,59 @@ MathJax.Hub.Config({
  • Including more classes
  • More classes
  • Friday September 23
  • -
  • Wisconsin Cancer Data
  • -
  • Using the correlation matrix
  • -
  • Discussing the correlation data
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Optimization, the central part of any Machine Learning algortithm
  • -
  • Revisiting our Logistic Regression case
  • -
  • The equations to solve
  • -
  • Solving using Newton-Raphson's method
  • -
  • Brief reminder on Newton-Raphson's method
  • -
  • The equations
  • -
  • Simple geometric interpretation
  • -
  • Extending to more than one variable
  • -
  • Steepest descent
  • -
  • More on Steepest descent
  • -
  • The ideal
  • -
  • The sensitiveness of the gradient descent
  • +
  • Searching for Optimal Regularization Parameters \( \lambda \)
  • +
  • Grid Search
  • +
  • Randomized Grid Search
  • +
  • Wisconsin Cancer Data
  • +
  • Using the correlation matrix
  • +
  • Discussing the correlation data
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Optimization, the central part of any Machine Learning algortithm
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Brief reminder on Newton-Raphson's method
  • +
  • The equations
  • +
  • Simple geometric interpretation
  • +
  • Extending to more than one variable
  • +
  • Steepest descent
  • +
  • More on Steepest descent
  • +
  • The ideal
  • +
  • The sensitiveness of the gradient descent
  • +
  • Revisiting our Logistic Regression case
  • +
  • The equations to solve
  • +
  • Solving using Newton-Raphson's method
  • +
  • Convex functions
  • +
  • Convex function
  • +
  • Conditions on convex functions
  • +
  • More on convex functions
  • +
  • Some simple problems
  • +
  • Standard steepest descent
  • +
  • Gradient method
  • +
  • Steepest descent method
  • +
  • Steepest descent method
  • +
  • Final expressions
  • +
  • Steepest descent example
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method and iterations
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Conjugate gradient method
  • +
  • Revisiting our first homework
  • +
  • Gradient descent example
  • +
  • The derivative of the cost/loss function
  • +
  • The Hessian matrix
  • +
  • Simple program
  • +
  • Gradient Descent Example
  • +
  • And a corresponding example using scikit-learn
  • +
  • Gradient descent and Ridge
  • +
  • The Hessian matrix for Ridge Regression
  • +
  • Program example for gradient descent with Ridge Regression
  • +
  • Using gradient descent methods, limitations
  • +
  • Challenge yourself this weekend
  • @@ -275,7 +412,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 42
  • +
  • 79
  • »
  • diff --git a/doc/pub/week38/html/week38-reveal.html b/doc/pub/week38/html/week38-reveal.html index 1ef4b71b3..aa056a55f 100644 --- a/doc/pub/week38/html/week38-reveal.html +++ b/doc/pub/week38/html/week38-reveal.html @@ -1068,6 +1068,249 @@ methods.

    Friday September 23

    +
    +

    Searching for Optimal Regularization Parameters \( \lambda \)

    + +

    In project 1, when using Ridge and Lasso regression, we end up +searching for the optimal parameter \( \lambda \) which minimizes our +selected scores (MSE or \( R2 \) values for example). The brute force +approach, as discussed in the code here for Ridge regression, consists +in evaluating the MSE as function of different \( \lambda \) values. +Based on these calculations, one tries then to determine the value of the hyperparameter \( \lambda \) +which results in optimal scores (for example the smallest MSE or an \( R2=1 \)). +

    + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 500
    +MSERidgePredict = np.zeros(nlambdas)
    +lambdas = np.logspace(-4, 2, nlambdas)
    +for i in range(nlambdas):
    +    lmb = lambdas[i]
    +    RegRidge = linear_model.Ridge(lmb)
    +    RegRidge.fit(X_train,y_train)
    +    ypredictRidge = RegRidge.predict(X_test)
    +    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    +
    +# Now plot the results
    +plt.figure()
    +plt.plot(np.log10(lambdas), MSERidgePredict, 'g--', label = 'MSE SL Ridge Test')
    +plt.xlabel('log10(lambda)')
    +plt.ylabel('MSE')
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here we have performed a rather data greedy calculation as function of the regularization parameter \( \lambda \). There is no resampling here. The latter can easily be added by employing the function RidgeCV instead of just calling the Ridge function. For RidgeCV we need to pass the array of \( \lambda \) values. +By inspecting the figure we can in turn determine which is the optimal regularization parameter. +This becomes however less functional in the long run. +

    +
    + +
    + + +

    An alternative is to use the so-called grid search functionality +included with the library Scikit-Learn, as demonstrated for the same +example here. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 10
    +lambdas = np.logspace(-4, 2, nlambdas)
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    By default the grid search function includes cross validation with +five folds. The Scikit-Learn +documentation +contains more information on how to set the different parameters. +

    + +

    If we take out the random noise, running the above codes results in \( \lambda=0 \) yielding the best fit.

    +
    + +
    + + +

    An alternative to the above manual grid set up, is to use a random +search where the parameters are tuned from a random distribution +(uniform below) for a fixed number of iterations. A model is +constructed and evaluated for each combination of chosen parameters. +We repeat the previous example but now with a random search. Note +that values of \( \lambda \) are now limited to be within \( x\in +[0,1] \). This domain may not be the most relevant one for the specific +case under study. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +from scipy.stats import uniform as randuniform
    +from sklearn.model_selection import RandomizedSearchCV
    +
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +param_grid = {'alpha': randuniform()}
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Wisconsin Cancer Data

    @@ -1630,6 +1873,1178 @@ randomness. One such method is that of Stochastic Gradient Descent

    +
    +

    Revisiting our Logistic Regression case

    + +

    In our discussion on Logistic Regression we studied the +case of +two classes, with \( y_i \) either +\( 0 \) or \( 1 \). Furthermore we assumed also that we have only two +parameters \( \beta \) in our fitting, that is we +defined probabilities +

    + +

     
    +$$ +\begin{align*} +p(y_i=1|x_i,\boldsymbol{\beta}) &= \frac{\exp{(\beta_0+\beta_1x_i)}}{1+\exp{(\beta_0+\beta_1x_i)}},\nonumber\\ +p(y_i=0|x_i,\boldsymbol{\beta}) &= 1 - p(y_i=1|x_i,\boldsymbol{\beta}), +\end{align*} +$$ +

     
    + +

    where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in our case \( \beta_0 \) and \( \beta_1 \).

    +
    + +
    +

    The equations to solve

    + +

    Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \) +elements \( y_i \), an \( n\times p \) matrix \( \boldsymbol{X} \) which contains the +\( x_i \) values and a vector \( \boldsymbol{p} \) of fitted probabilities +\( p(y_i\vert x_i,\boldsymbol{\beta}) \). We rewrote in a more compact form +the first derivative of the cost function as +

    + +

     
    +$$ +\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{p}\right). +$$ +

     
    + +

    If we in addition define a diagonal matrix \( \boldsymbol{W} \) with elements +\( p(y_i\vert x_i,\boldsymbol{\beta})(1-p(y_i\vert x_i,\boldsymbol{\beta}) \), we can obtain a compact expression of the second derivative as +

    + +

     
    +$$ +\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T} = \boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X}. +$$ +

     
    + +

    This defines what is called the Hessian matrix.

    +
    + +
    +

    Solving using Newton-Raphson's method

    + +

    If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.

    + +

    Our iterative scheme is then given by

    + +

     
    +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T}\right)^{-1}_{\boldsymbol{\beta}^{\mathrm{old}}}\times \left(\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}\right)_{\boldsymbol{\beta}^{\mathrm{old}}}, +$$ +

     
    + +

    or in matrix form as

    + +

     
    +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X} \right)^{-1}\times \left(-\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{p}) \right)_{\boldsymbol{\beta}^{\mathrm{old}}}. +$$ +

     
    + +

    The right-hand side is computed with the old values of \( \beta \).

    + +

    If we can compute these matrices, in particular the Hessian, the above is often the easiest method to implement.

    +
    + +
    +

    Convex functions

    + +

    Ideally we want our cost/loss function to be convex(concave).

    + +

    First we give the definition of a convex set: A set \( C \) in +\( \mathbb{R}^n \) is said to be convex if, for all \( x \) and \( y \) in \( C \) and +all \( t \in (0,1) \) , the point \( (1 − t)x + ty \) also belongs to +C. Geometrically this means that every point on the line segment +connecting \( x \) and \( y \) is in \( C \) as discussed below. +

    + +

    The convex subsets of \( \mathbb{R} \) are the intervals of +\( \mathbb{R} \). Examples of convex sets of \( \mathbb{R}^2 \) are the +regular polygons (triangles, rectangles, pentagons, etc...). +

    +
    + +
    +

    Convex function

    + +

    Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if

     
    +$$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$ +

     
    for all \( x_1, x_2 \in X \) and for all \( t \in [0,1] \). If \( \leq \) is replaced with a strict inequaltiy in the definition, we demand \( x_1 \neq x_2 \) and \( t\in(0,1) \) then \( f \) is said to be strictly convex. For a single variable function, convexity means that if you draw a straight line connecting \( f(x_1) \) and \( f(x_2) \), the value of the function on the interval \( [x_1,x_2] \) is always below the line as illustrated below.

    +
    + +
    +

    Conditions on convex functions

    + +

    In the following we state first and second-order conditions which +ensures convexity of a function \( f \). We write \( D_f \) to denote the +domain of \( f \), i.e the subset of \( R^n \) where \( f \) is defined. For more +details and proofs we refer to: S. Boyd and L. Vandenberghe. Convex Optimization. Cambridge University Press. +

    + +
    +First order condition +

    +

    Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for +all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \) +is a convex set and

     
    +$$f(y) \geq f(x) + \nabla f(x)^T (y-x) $$ +

     
    holds +for all \( x,y \in D_f \). This condition means that for a convex function +the first order Taylor expansion (right hand side above) at any point +a global under estimator of the function. To convince yourself you can +make a drawing of \( f(x) = x^2+1 \) and draw the tangent line to \( f(x) \) and +note that it is always below the graph. +

    +
    + + +
    +Second order condition +

    +

    Assume that \( f \) is twice +differentiable, i.e the Hessian matrix exists at each point in +\( D_f \). Then \( f \) is convex if and only if \( D_f \) is a convex set and its +Hessian is positive semi-definite for all \( x\in D_f \). For a +single-variable function this reduces to \( f''(x) \geq 0 \). Geometrically this means that \( f \) has nonnegative curvature +everywhere. +

    +
    + +

    This condition is particularly useful since it gives us an procedure for determining if the function under consideration is convex, apart from using the definition.

    +
    + +
    +

    More on convex functions

    + +

    The next result is of great importance to us and the reason why we are +going on about convex functions. In machine learning we frequently +have to minimize a loss/cost function in order to find the best +parameters for the model we are considering. +

    + +

    Ideally we want the +global minimum (for high-dimensional models it is hard to know +if we have local or global minimum). However, if the cost/loss function +is convex the following result provides invaluable information: +

    + +
    +Any minimum is global for convex functions +

    +

    Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \) +is minimal, where \( f \) is convex and differentiable. Then, any point +\( x^* \) that satisfies \( \nabla f(x^*) = 0 \) is a global minimum. +

    +
    + +

    This result means that if we know that the cost/loss function is convex and we are able to find a minimum, we are guaranteed that it is a global minimum.

    +
    + +
    +

    Some simple problems

    + +
      +

    1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
    2. +

    3. Using the second order condition show that the following functions are convex on the specified domain.
    4. +
        +

      • \( f(x) = e^x \) is convex for \( x \in \mathbb{R} \).
      • +

      • \( g(x) = -\ln(x) \) is convex for \( x \in (0,\infty) \).
      • +
      +

      +

    5. Let \( f(x) = x^2 \) and \( g(x) = e^x \). Show that \( f(g(x)) \) and \( g(f(x)) \) is convex for \( x \in \mathbb{R} \). Also show that if \( f(x) \) is any convex function than \( h(x) = e^{f(x)} \) is convex.
    6. +

    7. A norm is any function that satisfy the following properties
    8. +
        +

      • \( f(\alpha x) = |\alpha| f(x) \) for all \( \alpha \in \mathbb{R} \).
      • +

      • \( f(x+y) \leq f(x) + f(y) \)
      • +

      • \( f(x) \leq 0 \) for all \( x \in \mathbb{R}^n \) with equality if and only if \( x = 0 \)
      • +
      +

      +

    +

    +

    Using the definition of convexity, try to show that a function satisfying the properties above is convex (the third condition is not needed to show this).

    +
    + +
    +

    Standard steepest descent

    + +

    Before we proceed, we would like to discuss the approach called the +standard Steepest descent (different from the above steepest descent discussion), which again leads to us having to be able +to compute a matrix. It belongs to the class of Conjugate Gradient methods (CG). +

    + +The success of the CG method +

    for finding solutions of non-linear problems is based on the theory +of conjugate gradients for linear systems of equations. It belongs to +the class of iterative methods for solving problems from linear +algebra of the type +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}. +\end{equation*} +$$ +

     
    + +

    In the iterative process we end up with a problem like

    + +

     
    +$$ +\begin{equation*} + \boldsymbol{r}= \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}, +\end{equation*} +$$ +

     
    + +

    where \( \boldsymbol{r} \) is the so-called residual or error in the iterative process.

    + +

    When we have found the exact solution, \( \boldsymbol{r}=0 \).

    +
    + +
    +

    Gradient method

    + +

    The residual is zero when we reach the minimum of the quadratic equation

    +

     
    +$$ +\begin{equation*} + P(\boldsymbol{x})=\frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T\boldsymbol{b}, +\end{equation*} +$$ +

     
    + +

    with the constraint that the matrix \( \boldsymbol{A} \) is positive definite and +symmetric. This defines also the Hessian and we want it to be positive definite. +

    +
    + +
    +

    Steepest descent method

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ +

     
    + +

    or consider the system

    +

     
    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ +

     
    + +

    instead.

    +
    + +
    +

    Steepest descent method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +

     
    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ +

     
    + +

    This suggests taking the first basis vector \( \boldsymbol{r}_1 \) (see below for definition) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ +

     
    + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +

    +
    +
    + +
    +

    Final expressions

    +
    + +

    +

    We can compute the residual iteratively as

    +

     
    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ +

     
    + +

    which equals

    +

     
    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{r}_k), + \end{equation*} +$$ +

     
    + +

    or

    +

     
    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{r}_k, + \end{equation*} +$$ +

     
    + +

    which gives

    + +

     
    +$$ +\alpha_k = \frac{\boldsymbol{r}_k^T\boldsymbol{r}_k}{\boldsymbol{r}_k^T\boldsymbol{A}\boldsymbol{r}_k} +$$ +

     
    + +

    leading to the iterative scheme

    +

     
    +$$ +\begin{equation*} +\boldsymbol{x}_{k+1}=\boldsymbol{x}_k-\alpha_k\boldsymbol{r}_{k}, + \end{equation*} +$$ +

     
    +

    +
    + +
    +

    Steepest descent example

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import numpy.linalg as la
    +
    +import scipy.optimize as sopt
    +
    +import matplotlib.pyplot as pt
    +from mpl_toolkits.mplot3d import axes3d
    +
    +def f(x):
    +    return x[0]**2 + 3.0*x[1]**2
    +
    +def df(x):
    +    return np.array([2*x[0], 6*x[1]])
    +
    +fig = pt.figure()
    +ax = fig.gca(projection="3d")
    +
    +xmesh, ymesh = np.mgrid[-3:3:50j,-3:3:50j]
    +fmesh = f(np.array([xmesh, ymesh]))
    +ax.plot_surface(xmesh, ymesh, fmesh)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    And then as countor plot

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh)
    +guesses = [np.array([2, 2./5])]
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Find guesses

    + + +
    +
    +
    +
    +
    +
    x = guesses[-1]
    +s = -df(x)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Run it!

    + + +
    +
    +
    +
    +
    +
    def f1d(alpha):
    +    return f(x + alpha*s)
    +
    +alpha_opt = sopt.golden(f1d)
    +next_guess = x + alpha_opt * s
    +guesses.append(next_guess)
    +print(next_guess)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    What happened?

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh, 50)
    +it_array = np.array(guesses)
    +pt.plot(it_array.T[0], it_array.T[1], "x-")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Note that we did only one iteration here. We can easily add more using our previous guesses.

    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    In the CG method we define so-called conjugate directions and two vectors +\( \boldsymbol{s} \) and \( \boldsymbol{t} \) +are said to be +conjugate if +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{s}^T\boldsymbol{A}\boldsymbol{t}= 0. +\end{equation*} +$$ +

     
    + +

    The philosophy of the CG method is to perform searches in various conjugate directions +of our vectors \( \boldsymbol{x}_i \) obeying the above criterion, namely +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{x}_i^T\boldsymbol{A}\boldsymbol{x}_j= 0. +\end{equation*} +$$ +

     
    + +

    Two vectors are conjugate if they are orthogonal with respect to +this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s} \) is conjugate to \( \boldsymbol{t} \), then \( \boldsymbol{t} \) is conjugate to \( \boldsymbol{s} \). +

    +
    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    An example is given by the eigenvectors of the matrix

    +

     
    +$$ +\begin{equation*} +\boldsymbol{v}_i^T\boldsymbol{A}\boldsymbol{v}_j= \lambda\boldsymbol{v}_i^T\boldsymbol{v}_j, +\end{equation*} +$$ +

     
    + +

    which is zero unless \( i=j \).

    +
    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    Assume now that we have a symmetric positive-definite matrix \( \boldsymbol{A} \) of size +\( n\times n \). At each iteration \( i+1 \) we obtain the conjugate direction of a vector +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{x}_{i+1}=\boldsymbol{x}_{i}+\alpha_i\boldsymbol{p}_{i}. +\end{equation*} +$$ +

     
    + +

    We assume that \( \boldsymbol{p}_{i} \) is a sequence of \( n \) mutually conjugate directions. +Then the \( \boldsymbol{p}_{i} \) form a basis of \( R^n \) and we can expand the solution +$ \boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}$ in this basis, namely +

    + +

     
    +$$ +\begin{equation*} + \boldsymbol{x} = \sum^{n}_{i=1} \alpha_i \boldsymbol{p}_i. +\end{equation*} +$$ +

     
    +

    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    The coefficients are given by

    +

     
    +$$ +\begin{equation*} + \mathbf{A}\mathbf{x} = \sum^{n}_{i=1} \alpha_i \mathbf{A} \mathbf{p}_i = \mathbf{b}. +\end{equation*} +$$ +

     
    + +

    Multiplying with \( \boldsymbol{p}_k^T \) from the left gives

    + +

     
    +$$ +\begin{equation*} + \boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{x} = \sum^{n}_{i=1} \alpha_i\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{p}_i= \boldsymbol{p}_k^T \boldsymbol{b}, +\end{equation*} +$$ +

     
    + +

    and we can define the coefficients \( \alpha_k \) as

    + +

     
    +$$ +\begin{equation*} + \alpha_k = \frac{\boldsymbol{p}_k^T \boldsymbol{b}}{\boldsymbol{p}_k^T \boldsymbol{A} \boldsymbol{p}_k} +\end{equation*} +$$ +

     
    +

    +
    + +
    +

    Conjugate gradient method and iterations

    +
    + +

    + +

    If we choose the conjugate vectors \( \boldsymbol{p}_k \) carefully, +then we may not need all of them to obtain a good approximation to the solution +\( \boldsymbol{x} \). +We want to regard the conjugate gradient method as an iterative method. +This will us to solve systems where \( n \) is so large that the direct +method would take too much time. +

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ +

     
    + +

    or consider the system

    +

     
    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ +

     
    + +

    instead.

    +
    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +

     
    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ +

     
    + +

    This suggests taking the first basis vector \( \boldsymbol{p}_1 \) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ +

     
    + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +The other vectors in the basis will be conjugate to the gradient, +hence the name conjugate gradient method. +

    +
    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    Let \( \boldsymbol{r}_k \) be the residual at the \( k \)-th step:

    +

     
    +$$ +\begin{equation*} +\boldsymbol{r}_k=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k. +\end{equation*} +$$ +

     
    + +

    Note that \( \boldsymbol{r}_k \) is the negative gradient of \( f \) at +\( \boldsymbol{x}=\boldsymbol{x}_k \), +so the gradient descent method would be to move in the direction \( \boldsymbol{r}_k \). +Here, we insist that the directions \( \boldsymbol{p}_k \) are conjugate to each other, +so we take the direction closest to the gradient \( \boldsymbol{r}_k \) +under the conjugacy constraint. +This gives the following expression +

    +

     
    +$$ +\begin{equation*} +\boldsymbol{p}_{k+1}=\boldsymbol{r}_k-\frac{\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{r}_k}{\boldsymbol{p}_k^T\boldsymbol{A}\boldsymbol{p}_k} \boldsymbol{p}_k. +\end{equation*} +$$ +

     
    +

    +
    + +
    +

    Conjugate gradient method

    +
    + +

    +

    We can also compute the residual iteratively as

    +

     
    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ +

     
    + +

    which equals

    +

     
    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{p}_k), + \end{equation*} +$$ +

     
    + +

    or

    +

     
    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{p}_k, + \end{equation*} +$$ +

     
    + +

    which gives

    + +

     
    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{r}_k-\boldsymbol{A}\boldsymbol{p}_{k}, + \end{equation*} +$$ +

     
    +

    +
    + +
    +

    Revisiting our first homework

    + +

    We will use linear regression as a case study for the gradient descent +methods. Linear regression is a great test case for the gradient +descent methods discussed in the lectures since it has several +desirable properties such as: +

    + +
      +

    1. An analytical solution (recall homework set 1).
    2. +

    3. The gradient can be computed analytically.
    4. +

    5. The cost function is convex which guarantees that gradient descent converges for small enough learning rates
    6. +
    +

    +

    We revisit an example similar to what we had in the first homework set. We had a function of the type

    + + + +
    +
    +
    +
    +
    +
    x = 2*np.random.rand(m,1)
    +y = 4+3*x+np.random.randn(m,1)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    with \( x_i \in [0,1] \) is chosen randomly using a uniform distribution. Additionally we have a stochastic noise chosen according to a normal distribution \( \cal {N}(0,1) \). +The linear regression model is given by +

    +

     
    +$$ +h_\beta(x) = \boldsymbol{y} = \beta_0 + \beta_1 x, +$$ +

     
    + +

    such that

    +

     
    +$$ +\boldsymbol{y}_i = \beta_0 + \beta_1 x_i. +$$ +

     
    +

    + +
    +

    Gradient descent example

    + +

    Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)

    + +

    It is convenient to write \( \mathbf{\boldsymbol{y}} = X\beta \) where \( X \in \mathbb{R}^{100 \times 2} \) is the design matrix given by (we keep the intercept here)

    +

     
    +$$ +X \equiv \begin{bmatrix} +1 & x_1 \\ +\vdots & \vdots \\ +1 & x_{100} & \\ +\end{bmatrix}. +$$ +

     
    + +

    The cost/loss/risk function is given by (

    +

     
    +$$ +C(\beta) = \frac{1}{n}||X\beta-\mathbf{y}||_{2}^{2} = \frac{1}{n}\sum_{i=1}^{100}\left[ (\beta_0 + \beta_1 x_i)^2 - 2 y_i (\beta_0 + \beta_1 x_i) + y_i^2\right] +$$ +

     
    + +

    and we want to find \( \beta \) such that \( C(\beta) \) is minimized.

    +
    + +
    +

    The derivative of the cost/loss function

    + +

    Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as

    +

     
    +$$ +\nabla_{\beta} C(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} = \frac{2}{n}X^T(X\beta - \mathbf{y}), +$$ +

     
    + +

    where \( X \) is the design matrix defined above.

    +
    + +
    +

    The Hessian matrix

    +

    The Hessian matrix of \( C(\beta) \) is given by

    +

     
    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X. +$$ +

     
    + +

    This result implies that \( C(\beta) \) is a convex function since the matrix \( X^T X \) always is positive semi-definite.

    +
    + +
    +

    Simple program

    + +

    We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to

    +

     
    +$$ +\beta_{k+1} = \beta_k - \gamma \nabla_\beta C(\beta_k), \ k=0,1,\cdots +$$ +

     
    + +

    We can use the expression we computed for the gradient and let use a +\( \beta_0 \) be chosen randomly and let \( \gamma = 0.001 \). Stop iterating +when \( ||\nabla_\beta C(\beta_k) || \leq \epsilon = 10^{-8} \). Note that the code below does not include the latter stop criterion. +

    + +

    And finally we can compare our solution for \( \beta \) with the analytic result given by +\( \beta= (X^TX)^{-1} X^T \mathbf{y} \). +

    +
    + +
    +

    Gradient Descent Example

    + +

    Here our simple example

    + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +# Hessian matrix
    +H = (2.0/n)* X.T @ X
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y
    +print(beta_linreg)
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 1000
    +
    +for iter in range(Niterations):
    +    gradient = (2.0/n)*X.T @ (X @ beta-y)
    +    beta -= eta*gradient
    +
    +print(beta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(beta)
    +ypredict2 = xbnew.dot(beta_linreg)
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(xnew, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +

    And a corresponding example using scikit-learn

    + + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +beta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y)
    +print(beta_linreg)
    +sgdreg = SGDRegressor(max_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +

    Gradient descent and Ridge

    + +

    We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),

    +

     
    +$$ +C_{\text{ridge}}(\beta) = \frac{1}{n}||X\beta -\mathbf{y}||^2 + \lambda ||\beta||^2, \ \lambda \geq 0. +$$ +

     
    + +

    In order to minimize \( C_{\text{ridge}}(\beta) \) using GD we adjust the gradient as follows

    +

     
    +$$ +\nabla_\beta C_{\text{ridge}}(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} + 2\lambda\begin{bmatrix} \beta_0 \\ \beta_1\end{bmatrix} = 2 (\frac{1}{n}X^T(X\beta - \mathbf{y})+\lambda \beta). +$$ +

     
    + +

    We can easily extend our program to minimize \( C_{\text{ridge}}(\beta) \) using gradient descent and compare with the analytical solution given by

    +

     
    +$$ +\beta_{\text{ridge}} = \left(X^T X + n\lambda I_{2 \times 2} \right)^{-1} X^T \mathbf{y}. +$$ +

     
    +

    + +
    +

    The Hessian matrix for Ridge Regression

    +

    The Hessian matrix of Ridge Regression for our simple example is given by

    +

     
    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X+2\lambda\boldsymbol{I}. +$$ +

     
    + +

    This implies that the Hessian matrix is positive definite, hence the stationary point is a +minimum. +Note that the Ridge cost function is convex being a sum of two convex +functions. Therefore, the stationary point is a global +minimum of this function. +

    +
    + +
    +

    Program example for gradient descent with Ridge Regression

    + + +
    +
    +
    +
    +
    +
    from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +XT_X = X.T @ X
    +
    +#Ridge parameter lambda
    +lmbda  = 0.001
    +Id = n*lmbda* np.eye(XT_X.shape[0])
    +
    +# Hessian matrix
    +H = (2.0/n)* XT_X+2*lmbda* np.eye(XT_X.shape[0])
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +
    +beta_linreg = np.linalg.inv(XT_X+Id) @ X.T @ y
    +print(beta_linreg)
    +# Start plain gradient descent
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/n*X.T @ (X @ (beta)-y)+2*lmbda*beta
    +    beta -= eta*gradients
    +
    +print(beta)
    +ypredict = X @ beta
    +ypredict2 = X @ beta_linreg
    +plt.plot(x, ypredict, "r-")
    +plt.plot(x, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example for Ridge')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +

    Using gradient descent methods, limitations

    + +
      +

    • Gradient descent (GD) finds local minima of our function. Since the GD algorithm is deterministic, if it converges, it will converge to a local minimum of our cost/loss/risk function. Because in ML we are often dealing with extremely rugged landscapes with many local minima, this can lead to poor performance.
    • +

    • GD is sensitive to initial conditions. One consequence of the local nature of GD is that initial conditions matter. Depending on where one starts, one will end up at a different local minima. Therefore, it is very important to think about how one initializes the training process. This is true for GD as well as more complicated variants of GD.
    • +

    • Gradients are computationally expensive to calculate for large datasets. In many cases in statistics and ML, the cost/loss/risk function is a sum of terms, with one term for each data point. For example, in linear regression, \( E \propto \sum_{i=1}^n (y_i - \mathbf{w}^T\cdot\mathbf{x}_i)^2 \); for logistic regression, the square error is replaced by the cross entropy. To calculate the gradient we have to sum over all \( n \) data points. Doing this at every GD step becomes extremely computationally expensive. An ingenious solution to this, is to calculate the gradients using small subsets of the data called "mini batches". This has the added benefit of introducing stochasticity into our algorithm.
    • +

    • GD is very sensitive to choices of learning rates. GD is extremely sensitive to the choice of learning rates. If the learning rate is very small, the training process take an extremely long time. For larger learning rates, GD can diverge and give poor results. Furthermore, depending on what the local landscape looks like, we have to modify the learning rates to ensure convergence. Ideally, we would adaptively choose the learning rates to match the landscape.
    • +

    • GD treats all directions in parameter space uniformly. Another major drawback of GD is that unlike Newton's method, the learning rate for GD is the same in all directions in parameter space. For this reason, the maximum learning rate is set by the behavior of the steepest direction and this can significantly slow down training. Ideally, we would like to take large steps in flat directions and small steps in steep directions. Since we are exploring rugged landscapes where curvatures change, this requires us to keep track of not only the gradient but second derivatives. The ideal scenario would be to calculate the Hessian but this proves to be too computationally expensive.
    • +

    • GD can take exponential time to escape saddle points, even with random initialization. As we mentioned, GD is extremely sensitive to initial condition since it determines the particular local minimum GD would eventually reach. However, even with a good initialization scheme, through the introduction of randomness, GD can still take exponential time to escape saddle points.
    • +
    +
    + +
    +

    Challenge yourself this weekend

    + +

    Write a code which implements gradient descent for a logistic regression example.

    +
    +
    diff --git a/doc/pub/week38/html/week38-solarized.html b/doc/pub/week38/html/week38-solarized.html index b5fa54032..899b48b67 100644 --- a/doc/pub/week38/html/week38-solarized.html +++ b/doc/pub/week38/html/week38-solarized.html @@ -23,6 +23,32 @@ pre { border: 0pt solid #93a1a1; box-shadow: none; } +.alert-text-small { font-size: 80%; } +.alert-text-large { font-size: 130%; } +.alert-text-normal { font-size: 90%; } +.alert { + padding:8px 35px 8px 14px; margin-bottom:18px; + text-shadow:0 1px 0 rgba(255,255,255,0.5); + border:1px solid #93a1a1; + border-radius: 4px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + color: #555; + background-color: #eee8d5; + background-position: 10px 5px; + background-repeat: no-repeat; + background-size: 38px; + padding-left: 55px; + width: 75%; + } +.alert-block {padding-top:14px; padding-bottom:14px} +.alert-block > p, .alert-block > ul {margin-bottom:1em} +.alert li {margin-top: 1em} +.alert-block p+p {margin-top:5px} +.alert-notice { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_notice.png); } +.alert-summary { background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_summary.png); } +.alert-warning { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_warning.png); } +.alert-question {background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_question.png); } div { text-align: justify; text-justify: inter-word; } .tab { padding-left: 1.5em; @@ -100,6 +126,12 @@ div.toc p,a { ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -146,7 +178,101 @@ div.toc p,a { ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -983,6 +1109,247 @@ methods.









    Friday September 23

    +









    +

    Searching for Optimal Regularization Parameters \( \lambda \)

    + +

    In project 1, when using Ridge and Lasso regression, we end up +searching for the optimal parameter \( \lambda \) which minimizes our +selected scores (MSE or \( R2 \) values for example). The brute force +approach, as discussed in the code here for Ridge regression, consists +in evaluating the MSE as function of different \( \lambda \) values. +Based on these calculations, one tries then to determine the value of the hyperparameter \( \lambda \) +which results in optimal scores (for example the smallest MSE or an \( R2=1 \)). +

    + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 500
    +MSERidgePredict = np.zeros(nlambdas)
    +lambdas = np.logspace(-4, 2, nlambdas)
    +for i in range(nlambdas):
    +    lmb = lambdas[i]
    +    RegRidge = linear_model.Ridge(lmb)
    +    RegRidge.fit(X_train,y_train)
    +    ypredictRidge = RegRidge.predict(X_test)
    +    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    +
    +# Now plot the results
    +plt.figure()
    +plt.plot(np.log10(lambdas), MSERidgePredict, 'g--', label = 'MSE SL Ridge Test')
    +plt.xlabel('log10(lambda)')
    +plt.ylabel('MSE')
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here we have performed a rather data greedy calculation as function of the regularization parameter \( \lambda \). There is no resampling here. The latter can easily be added by employing the function RidgeCV instead of just calling the Ridge function. For RidgeCV we need to pass the array of \( \lambda \) values. +By inspecting the figure we can in turn determine which is the optimal regularization parameter. +This becomes however less functional in the long run. +

    + +









    + + +

    An alternative is to use the so-called grid search functionality +included with the library Scikit-Learn, as demonstrated for the same +example here. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 10
    +lambdas = np.logspace(-4, 2, nlambdas)
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    By default the grid search function includes cross validation with +five folds. The Scikit-Learn +documentation +contains more information on how to set the different parameters. +

    + +

    If we take out the random noise, running the above codes results in \( \lambda=0 \) yielding the best fit.

    + +









    + + +

    An alternative to the above manual grid set up, is to use a random +search where the parameters are tuned from a random distribution +(uniform below) for a fixed number of iterations. A model is +constructed and evaluated for each combination of chosen parameters. +We repeat the previous example but now with a random search. Note +that values of \( \lambda \) are now limited to be within \( x\in +[0,1] \). This domain may not be the most relevant one for the specific +case under study. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +from scipy.stats import uniform as randuniform
    +from sklearn.model_selection import RandomizedSearchCV
    +
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +param_grid = {'alpha': randuniform()}
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +









    Wisconsin Cancer Data

    @@ -1501,6 +1868,1060 @@ randomness. One such method is that of Stochastic Gradient Descent (SGD), see below.

    +









    +

    Revisiting our Logistic Regression case

    + +

    In our discussion on Logistic Regression we studied the +case of +two classes, with \( y_i \) either +\( 0 \) or \( 1 \). Furthermore we assumed also that we have only two +parameters \( \beta \) in our fitting, that is we +defined probabilities +

    + +$$ +\begin{align*} +p(y_i=1|x_i,\boldsymbol{\beta}) &= \frac{\exp{(\beta_0+\beta_1x_i)}}{1+\exp{(\beta_0+\beta_1x_i)}},\nonumber\\ +p(y_i=0|x_i,\boldsymbol{\beta}) &= 1 - p(y_i=1|x_i,\boldsymbol{\beta}), +\end{align*} +$$ + +

    where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in our case \( \beta_0 \) and \( \beta_1 \).

    + +









    +

    The equations to solve

    + +

    Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \) +elements \( y_i \), an \( n\times p \) matrix \( \boldsymbol{X} \) which contains the +\( x_i \) values and a vector \( \boldsymbol{p} \) of fitted probabilities +\( p(y_i\vert x_i,\boldsymbol{\beta}) \). We rewrote in a more compact form +the first derivative of the cost function as +

    + +$$ +\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{p}\right). +$$ + +

    If we in addition define a diagonal matrix \( \boldsymbol{W} \) with elements +\( p(y_i\vert x_i,\boldsymbol{\beta})(1-p(y_i\vert x_i,\boldsymbol{\beta}) \), we can obtain a compact expression of the second derivative as +

    + +$$ +\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T} = \boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X}. +$$ + +

    This defines what is called the Hessian matrix.

    + +









    +

    Solving using Newton-Raphson's method

    + +

    If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.

    + +

    Our iterative scheme is then given by

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T}\right)^{-1}_{\boldsymbol{\beta}^{\mathrm{old}}}\times \left(\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}\right)_{\boldsymbol{\beta}^{\mathrm{old}}}, +$$ + +

    or in matrix form as

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X} \right)^{-1}\times \left(-\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{p}) \right)_{\boldsymbol{\beta}^{\mathrm{old}}}. +$$ + +

    The right-hand side is computed with the old values of \( \beta \).

    + +

    If we can compute these matrices, in particular the Hessian, the above is often the easiest method to implement.

    + + +

    Convex functions

    + +

    Ideally we want our cost/loss function to be convex(concave).

    + +

    First we give the definition of a convex set: A set \( C \) in +\( \mathbb{R}^n \) is said to be convex if, for all \( x \) and \( y \) in \( C \) and +all \( t \in (0,1) \) , the point \( (1 − t)x + ty \) also belongs to +C. Geometrically this means that every point on the line segment +connecting \( x \) and \( y \) is in \( C \) as discussed below. +

    + +

    The convex subsets of \( \mathbb{R} \) are the intervals of +\( \mathbb{R} \). Examples of convex sets of \( \mathbb{R}^2 \) are the +regular polygons (triangles, rectangles, pentagons, etc...). +

    + +









    +

    Convex function

    + +

    Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if $$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$ for all \( x_1, x_2 \in X \) and for all \( t \in [0,1] \). If \( \leq \) is replaced with a strict inequaltiy in the definition, we demand \( x_1 \neq x_2 \) and \( t\in(0,1) \) then \( f \) is said to be strictly convex. For a single variable function, convexity means that if you draw a straight line connecting \( f(x_1) \) and \( f(x_2) \), the value of the function on the interval \( [x_1,x_2] \) is always below the line as illustrated below.

    + +









    +

    Conditions on convex functions

    + +

    In the following we state first and second-order conditions which +ensures convexity of a function \( f \). We write \( D_f \) to denote the +domain of \( f \), i.e the subset of \( R^n \) where \( f \) is defined. For more +details and proofs we refer to: S. Boyd and L. Vandenberghe. Convex Optimization. Cambridge University Press. +

    + +
    +First order condition +

    +

    Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for +all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \) +is a convex set and $$f(y) \geq f(x) + \nabla f(x)^T (y-x) $$ holds +for all \( x,y \in D_f \). This condition means that for a convex function +the first order Taylor expansion (right hand side above) at any point +a global under estimator of the function. To convince yourself you can +make a drawing of \( f(x) = x^2+1 \) and draw the tangent line to \( f(x) \) and +note that it is always below the graph. +

    +
    + + +
    +Second order condition +

    +

    Assume that \( f \) is twice +differentiable, i.e the Hessian matrix exists at each point in +\( D_f \). Then \( f \) is convex if and only if \( D_f \) is a convex set and its +Hessian is positive semi-definite for all \( x\in D_f \). For a +single-variable function this reduces to \( f''(x) \geq 0 \). Geometrically this means that \( f \) has nonnegative curvature +everywhere. +

    +
    + + +

    This condition is particularly useful since it gives us an procedure for determining if the function under consideration is convex, apart from using the definition.

    + +









    +

    More on convex functions

    + +

    The next result is of great importance to us and the reason why we are +going on about convex functions. In machine learning we frequently +have to minimize a loss/cost function in order to find the best +parameters for the model we are considering. +

    + +

    Ideally we want the +global minimum (for high-dimensional models it is hard to know +if we have local or global minimum). However, if the cost/loss function +is convex the following result provides invaluable information: +

    + +
    +Any minimum is global for convex functions +

    +

    Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \) +is minimal, where \( f \) is convex and differentiable. Then, any point +\( x^* \) that satisfies \( \nabla f(x^*) = 0 \) is a global minimum. +

    +
    + + +

    This result means that if we know that the cost/loss function is convex and we are able to find a minimum, we are guaranteed that it is a global minimum.

    + +









    +

    Some simple problems

    + +
      +
    1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
    2. +
    3. Using the second order condition show that the following functions are convex on the specified domain.
    4. +
        +
      • \( f(x) = e^x \) is convex for \( x \in \mathbb{R} \).
      • +
      • \( g(x) = -\ln(x) \) is convex for \( x \in (0,\infty) \).
      • +
      +
    5. Let \( f(x) = x^2 \) and \( g(x) = e^x \). Show that \( f(g(x)) \) and \( g(f(x)) \) is convex for \( x \in \mathbb{R} \). Also show that if \( f(x) \) is any convex function than \( h(x) = e^{f(x)} \) is convex.
    6. +
    7. A norm is any function that satisfy the following properties
    8. +
        +
      • \( f(\alpha x) = |\alpha| f(x) \) for all \( \alpha \in \mathbb{R} \).
      • +
      • \( f(x+y) \leq f(x) + f(y) \)
      • +
      • \( f(x) \leq 0 \) for all \( x \in \mathbb{R}^n \) with equality if and only if \( x = 0 \)
      • +
      +
    +

    Using the definition of convexity, try to show that a function satisfying the properties above is convex (the third condition is not needed to show this).

    + +









    +

    Standard steepest descent

    + +

    Before we proceed, we would like to discuss the approach called the +standard Steepest descent (different from the above steepest descent discussion), which again leads to us having to be able +to compute a matrix. It belongs to the class of Conjugate Gradient methods (CG). +

    + +The success of the CG method +

    for finding solutions of non-linear problems is based on the theory +of conjugate gradients for linear systems of equations. It belongs to +the class of iterative methods for solving problems from linear +algebra of the type +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}. +\end{equation*} +$$ + +

    In the iterative process we end up with a problem like

    + +$$ +\begin{equation*} + \boldsymbol{r}= \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}, +\end{equation*} +$$ + +

    where \( \boldsymbol{r} \) is the so-called residual or error in the iterative process.

    + +

    When we have found the exact solution, \( \boldsymbol{r}=0 \).

    + +









    +

    Gradient method

    + +

    The residual is zero when we reach the minimum of the quadratic equation

    +$$ +\begin{equation*} + P(\boldsymbol{x})=\frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T\boldsymbol{b}, +\end{equation*} +$$ + +

    with the constraint that the matrix \( \boldsymbol{A} \) is positive definite and +symmetric. This defines also the Hessian and we want it to be positive definite. +

    + +









    +

    Steepest descent method

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ + +

    or consider the system

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ + +

    instead.

    + +









    +

    Steepest descent method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ + +

    This suggests taking the first basis vector \( \boldsymbol{r}_1 \) (see below for definition) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +

    +
    + + +









    +

    Final expressions

    +
    + +

    +

    We can compute the residual iteratively as

    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ + +

    which equals

    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{r}_k), + \end{equation*} +$$ + +

    or

    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{r}_k, + \end{equation*} +$$ + +

    which gives

    + +$$ +\alpha_k = \frac{\boldsymbol{r}_k^T\boldsymbol{r}_k}{\boldsymbol{r}_k^T\boldsymbol{A}\boldsymbol{r}_k} +$$ + +

    leading to the iterative scheme

    +$$ +\begin{equation*} +\boldsymbol{x}_{k+1}=\boldsymbol{x}_k-\alpha_k\boldsymbol{r}_{k}, + \end{equation*} +$$ +
    + + +









    +

    Steepest descent example

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import numpy.linalg as la
    +
    +import scipy.optimize as sopt
    +
    +import matplotlib.pyplot as pt
    +from mpl_toolkits.mplot3d import axes3d
    +
    +def f(x):
    +    return x[0]**2 + 3.0*x[1]**2
    +
    +def df(x):
    +    return np.array([2*x[0], 6*x[1]])
    +
    +fig = pt.figure()
    +ax = fig.gca(projection="3d")
    +
    +xmesh, ymesh = np.mgrid[-3:3:50j,-3:3:50j]
    +fmesh = f(np.array([xmesh, ymesh]))
    +ax.plot_surface(xmesh, ymesh, fmesh)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    And then as countor plot

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh)
    +guesses = [np.array([2, 2./5])]
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Find guesses

    + + +
    +
    +
    +
    +
    +
    x = guesses[-1]
    +s = -df(x)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Run it!

    + + +
    +
    +
    +
    +
    +
    def f1d(alpha):
    +    return f(x + alpha*s)
    +
    +alpha_opt = sopt.golden(f1d)
    +next_guess = x + alpha_opt * s
    +guesses.append(next_guess)
    +print(next_guess)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    What happened?

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh, 50)
    +it_array = np.array(guesses)
    +pt.plot(it_array.T[0], it_array.T[1], "x-")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Note that we did only one iteration here. We can easily add more using our previous guesses.

    + +









    +

    Conjugate gradient method

    +
    + +

    +

    In the CG method we define so-called conjugate directions and two vectors +\( \boldsymbol{s} \) and \( \boldsymbol{t} \) +are said to be +conjugate if +

    +$$ +\begin{equation*} +\boldsymbol{s}^T\boldsymbol{A}\boldsymbol{t}= 0. +\end{equation*} +$$ + +

    The philosophy of the CG method is to perform searches in various conjugate directions +of our vectors \( \boldsymbol{x}_i \) obeying the above criterion, namely +

    +$$ +\begin{equation*} +\boldsymbol{x}_i^T\boldsymbol{A}\boldsymbol{x}_j= 0. +\end{equation*} +$$ + +

    Two vectors are conjugate if they are orthogonal with respect to +this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s} \) is conjugate to \( \boldsymbol{t} \), then \( \boldsymbol{t} \) is conjugate to \( \boldsymbol{s} \). +

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    An example is given by the eigenvectors of the matrix

    +$$ +\begin{equation*} +\boldsymbol{v}_i^T\boldsymbol{A}\boldsymbol{v}_j= \lambda\boldsymbol{v}_i^T\boldsymbol{v}_j, +\end{equation*} +$$ + +

    which is zero unless \( i=j \).

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    Assume now that we have a symmetric positive-definite matrix \( \boldsymbol{A} \) of size +\( n\times n \). At each iteration \( i+1 \) we obtain the conjugate direction of a vector +

    +$$ +\begin{equation*} +\boldsymbol{x}_{i+1}=\boldsymbol{x}_{i}+\alpha_i\boldsymbol{p}_{i}. +\end{equation*} +$$ + +

    We assume that \( \boldsymbol{p}_{i} \) is a sequence of \( n \) mutually conjugate directions. +Then the \( \boldsymbol{p}_{i} \) form a basis of \( R^n \) and we can expand the solution +$ \boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}$ in this basis, namely +

    + +$$ +\begin{equation*} + \boldsymbol{x} = \sum^{n}_{i=1} \alpha_i \boldsymbol{p}_i. +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    The coefficients are given by

    +$$ +\begin{equation*} + \mathbf{A}\mathbf{x} = \sum^{n}_{i=1} \alpha_i \mathbf{A} \mathbf{p}_i = \mathbf{b}. +\end{equation*} +$$ + +

    Multiplying with \( \boldsymbol{p}_k^T \) from the left gives

    + +$$ +\begin{equation*} + \boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{x} = \sum^{n}_{i=1} \alpha_i\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{p}_i= \boldsymbol{p}_k^T \boldsymbol{b}, +\end{equation*} +$$ + +

    and we can define the coefficients \( \alpha_k \) as

    + +$$ +\begin{equation*} + \alpha_k = \frac{\boldsymbol{p}_k^T \boldsymbol{b}}{\boldsymbol{p}_k^T \boldsymbol{A} \boldsymbol{p}_k} +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method and iterations

    +
    + +

    + +

    If we choose the conjugate vectors \( \boldsymbol{p}_k \) carefully, +then we may not need all of them to obtain a good approximation to the solution +\( \boldsymbol{x} \). +We want to regard the conjugate gradient method as an iterative method. +This will us to solve systems where \( n \) is so large that the direct +method would take too much time. +

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ + +

    or consider the system

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ + +

    instead.

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ + +

    This suggests taking the first basis vector \( \boldsymbol{p}_1 \) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +The other vectors in the basis will be conjugate to the gradient, +hence the name conjugate gradient method. +

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    Let \( \boldsymbol{r}_k \) be the residual at the \( k \)-th step:

    +$$ +\begin{equation*} +\boldsymbol{r}_k=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k. +\end{equation*} +$$ + +

    Note that \( \boldsymbol{r}_k \) is the negative gradient of \( f \) at +\( \boldsymbol{x}=\boldsymbol{x}_k \), +so the gradient descent method would be to move in the direction \( \boldsymbol{r}_k \). +Here, we insist that the directions \( \boldsymbol{p}_k \) are conjugate to each other, +so we take the direction closest to the gradient \( \boldsymbol{r}_k \) +under the conjugacy constraint. +This gives the following expression +

    +$$ +\begin{equation*} +\boldsymbol{p}_{k+1}=\boldsymbol{r}_k-\frac{\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{r}_k}{\boldsymbol{p}_k^T\boldsymbol{A}\boldsymbol{p}_k} \boldsymbol{p}_k. +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    We can also compute the residual iteratively as

    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ + +

    which equals

    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{p}_k), + \end{equation*} +$$ + +

    or

    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{p}_k, + \end{equation*} +$$ + +

    which gives

    + +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{r}_k-\boldsymbol{A}\boldsymbol{p}_{k}, + \end{equation*} +$$ +
    + + + +

    Revisiting our first homework

    + +

    We will use linear regression as a case study for the gradient descent +methods. Linear regression is a great test case for the gradient +descent methods discussed in the lectures since it has several +desirable properties such as: +

    + +
      +
    1. An analytical solution (recall homework set 1).
    2. +
    3. The gradient can be computed analytically.
    4. +
    5. The cost function is convex which guarantees that gradient descent converges for small enough learning rates
    6. +
    +

    We revisit an example similar to what we had in the first homework set. We had a function of the type

    + + + +
    +
    +
    +
    +
    +
    x = 2*np.random.rand(m,1)
    +y = 4+3*x+np.random.randn(m,1)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    with \( x_i \in [0,1] \) is chosen randomly using a uniform distribution. Additionally we have a stochastic noise chosen according to a normal distribution \( \cal {N}(0,1) \). +The linear regression model is given by +

    +$$ +h_\beta(x) = \boldsymbol{y} = \beta_0 + \beta_1 x, +$$ + +

    such that

    +$$ +\boldsymbol{y}_i = \beta_0 + \beta_1 x_i. +$$ + + + +

    Gradient descent example

    + +

    Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)

    + +

    It is convenient to write \( \mathbf{\boldsymbol{y}} = X\beta \) where \( X \in \mathbb{R}^{100 \times 2} \) is the design matrix given by (we keep the intercept here)

    +$$ +X \equiv \begin{bmatrix} +1 & x_1 \\ +\vdots & \vdots \\ +1 & x_{100} & \\ +\end{bmatrix}. +$$ + +

    The cost/loss/risk function is given by (

    +$$ +C(\beta) = \frac{1}{n}||X\beta-\mathbf{y}||_{2}^{2} = \frac{1}{n}\sum_{i=1}^{100}\left[ (\beta_0 + \beta_1 x_i)^2 - 2 y_i (\beta_0 + \beta_1 x_i) + y_i^2\right] +$$ + +

    and we want to find \( \beta \) such that \( C(\beta) \) is minimized.

    + +









    +

    The derivative of the cost/loss function

    + +

    Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as

    +$$ +\nabla_{\beta} C(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} = \frac{2}{n}X^T(X\beta - \mathbf{y}), +$$ + +

    where \( X \) is the design matrix defined above.

    + +









    +

    The Hessian matrix

    +

    The Hessian matrix of \( C(\beta) \) is given by

    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X. +$$ + +

    This result implies that \( C(\beta) \) is a convex function since the matrix \( X^T X \) always is positive semi-definite.

    + +









    +

    Simple program

    + +

    We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to

    +$$ +\beta_{k+1} = \beta_k - \gamma \nabla_\beta C(\beta_k), \ k=0,1,\cdots +$$ + +

    We can use the expression we computed for the gradient and let use a +\( \beta_0 \) be chosen randomly and let \( \gamma = 0.001 \). Stop iterating +when \( ||\nabla_\beta C(\beta_k) || \leq \epsilon = 10^{-8} \). Note that the code below does not include the latter stop criterion. +

    + +

    And finally we can compare our solution for \( \beta \) with the analytic result given by +\( \beta= (X^TX)^{-1} X^T \mathbf{y} \). +

    + +









    +

    Gradient Descent Example

    + +

    Here our simple example

    + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +# Hessian matrix
    +H = (2.0/n)* X.T @ X
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y
    +print(beta_linreg)
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 1000
    +
    +for iter in range(Niterations):
    +    gradient = (2.0/n)*X.T @ (X @ beta-y)
    +    beta -= eta*gradient
    +
    +print(beta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(beta)
    +ypredict2 = xbnew.dot(beta_linreg)
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(xnew, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +









    +

    And a corresponding example using scikit-learn

    + + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +beta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y)
    +print(beta_linreg)
    +sgdreg = SGDRegressor(max_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + +

    Gradient descent and Ridge

    + +

    We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),

    +$$ +C_{\text{ridge}}(\beta) = \frac{1}{n}||X\beta -\mathbf{y}||^2 + \lambda ||\beta||^2, \ \lambda \geq 0. +$$ + +

    In order to minimize \( C_{\text{ridge}}(\beta) \) using GD we adjust the gradient as follows

    +$$ +\nabla_\beta C_{\text{ridge}}(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} + 2\lambda\begin{bmatrix} \beta_0 \\ \beta_1\end{bmatrix} = 2 (\frac{1}{n}X^T(X\beta - \mathbf{y})+\lambda \beta). +$$ + +

    We can easily extend our program to minimize \( C_{\text{ridge}}(\beta) \) using gradient descent and compare with the analytical solution given by

    +$$ +\beta_{\text{ridge}} = \left(X^T X + n\lambda I_{2 \times 2} \right)^{-1} X^T \mathbf{y}. +$$ + + +









    +

    The Hessian matrix for Ridge Regression

    +

    The Hessian matrix of Ridge Regression for our simple example is given by

    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X+2\lambda\boldsymbol{I}. +$$ + +

    This implies that the Hessian matrix is positive definite, hence the stationary point is a +minimum. +Note that the Ridge cost function is convex being a sum of two convex +functions. Therefore, the stationary point is a global +minimum of this function. +

    + +









    +

    Program example for gradient descent with Ridge Regression

    + + +
    +
    +
    +
    +
    +
    from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +XT_X = X.T @ X
    +
    +#Ridge parameter lambda
    +lmbda  = 0.001
    +Id = n*lmbda* np.eye(XT_X.shape[0])
    +
    +# Hessian matrix
    +H = (2.0/n)* XT_X+2*lmbda* np.eye(XT_X.shape[0])
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +
    +beta_linreg = np.linalg.inv(XT_X+Id) @ X.T @ y
    +print(beta_linreg)
    +# Start plain gradient descent
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/n*X.T @ (X @ (beta)-y)+2*lmbda*beta
    +    beta -= eta*gradients
    +
    +print(beta)
    +ypredict = X @ beta
    +ypredict2 = X @ beta_linreg
    +plt.plot(x, ypredict, "r-")
    +plt.plot(x, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example for Ridge')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +









    +

    Using gradient descent methods, limitations

    + + +









    +

    Challenge yourself this weekend

    + +

    Write a code which implements gradient descent for a logistic regression example.

    +
    © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license diff --git a/doc/pub/week38/html/week38.html b/doc/pub/week38/html/week38.html index 23a6046f5..332960e54 100644 --- a/doc/pub/week38/html/week38.html +++ b/doc/pub/week38/html/week38.html @@ -100,6 +100,32 @@ div.output_text { color: #000; line-height: 1.21429em; } +.alert-text-small { font-size: 80%; } +.alert-text-large { font-size: 130%; } +.alert-text-normal { font-size: 90%; } +.alert { + padding:8px 35px 8px 14px; margin-bottom:18px; + text-shadow:0 1px 0 rgba(255,255,255,0.5); + border:1px solid #bababa; + border-radius: 4px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + color: #555; + background-color: #f8f8f8; + background-position: 10px 5px; + background-repeat: no-repeat; + background-size: 38px; + padding-left: 55px; + width: 75%; + } +.alert-block {padding-top:14px; padding-bottom:14px} +.alert-block > p, .alert-block > ul {margin-bottom:1em} +.alert li {margin-top: 1em} +.alert-block p+p {margin-top:5px} +.alert-notice { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_notice.png); } +.alert-summary { background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_summary.png); } +.alert-warning { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_warning.png); } +.alert-question {background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_question.png); } div { text-align: justify; text-justify: inter-word; } .tab { padding-left: 1.5em; @@ -177,6 +203,12 @@ div.toc p,a { ('Including more classes', 2, None, 'including-more-classes'), ('More classes', 2, None, 'more-classes'), ('Friday September 23', 2, None, 'friday-september-23'), + ('Searching for Optimal Regularization Parameters $\\lambda$', + 2, + None, + 'searching-for-optimal-regularization-parameters-lambda'), + ('Grid Search', 2, None, 'grid-search'), + ('Randomized Grid Search', 2, None, 'randomized-grid-search'), ('Wisconsin Cancer Data', 2, None, 'wisconsin-cancer-data'), ('Using the correlation matrix', 2, @@ -223,7 +255,101 @@ div.toc p,a { ('The sensitiveness of the gradient descent', 2, None, - 'the-sensitiveness-of-the-gradient-descent')]} + 'the-sensitiveness-of-the-gradient-descent'), + ('Revisiting our Logistic Regression case', + 2, + None, + 'revisiting-our-logistic-regression-case'), + ('The equations to solve', 2, None, 'the-equations-to-solve'), + ("Solving using Newton-Raphson's method", + 2, + None, + 'solving-using-newton-raphson-s-method'), + ('Convex functions', 2, None, 'convex-functions'), + ('Convex function', 2, None, 'convex-function'), + ('Conditions on convex functions', + 2, + None, + 'conditions-on-convex-functions'), + ('More on convex functions', 2, None, 'more-on-convex-functions'), + ('Some simple problems', 2, None, 'some-simple-problems'), + ('Standard steepest descent', + 2, + None, + 'standard-steepest-descent'), + ('Gradient method', 2, None, 'gradient-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Steepest descent method', 2, None, 'steepest-descent-method'), + ('Final expressions', 2, None, 'final-expressions'), + ('Steepest descent example', 2, None, 'steepest-descent-example'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method and iterations', + 2, + None, + 'conjugate-gradient-method-and-iterations'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Conjugate gradient method', + 2, + None, + 'conjugate-gradient-method'), + ('Revisiting our first homework', + 2, + None, + 'revisiting-our-first-homework'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', + 2, + None, + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('And a corresponding example using _scikit-learn_', + 2, + None, + 'and-a-corresponding-example-using-scikit-learn'), + ('Gradient descent and Ridge', + 2, + None, + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', + 2, + None, + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', + 2, + None, + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', + 2, + None, + 'using-gradient-descent-methods-limitations'), + ('Challenge yourself this weekend', + 2, + None, + 'challenge-yourself-this-weekend')]} end of tocinfo --> @@ -1060,6 +1186,247 @@ methods.









    Friday September 23

    +









    +

    Searching for Optimal Regularization Parameters \( \lambda \)

    + +

    In project 1, when using Ridge and Lasso regression, we end up +searching for the optimal parameter \( \lambda \) which minimizes our +selected scores (MSE or \( R2 \) values for example). The brute force +approach, as discussed in the code here for Ridge regression, consists +in evaluating the MSE as function of different \( \lambda \) values. +Based on these calculations, one tries then to determine the value of the hyperparameter \( \lambda \) +which results in optimal scores (for example the smallest MSE or an \( R2=1 \)). +

    + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.model_selection import train_test_split
    +from sklearn import linear_model
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 500
    +MSERidgePredict = np.zeros(nlambdas)
    +lambdas = np.logspace(-4, 2, nlambdas)
    +for i in range(nlambdas):
    +    lmb = lambdas[i]
    +    RegRidge = linear_model.Ridge(lmb)
    +    RegRidge.fit(X_train,y_train)
    +    ypredictRidge = RegRidge.predict(X_test)
    +    MSERidgePredict[i] = MSE(y_test,ypredictRidge)
    +
    +# Now plot the results
    +plt.figure()
    +plt.plot(np.log10(lambdas), MSERidgePredict, 'g--', label = 'MSE SL Ridge Test')
    +plt.xlabel('log10(lambda)')
    +plt.ylabel('MSE')
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here we have performed a rather data greedy calculation as function of the regularization parameter \( \lambda \). There is no resampling here. The latter can easily be added by employing the function RidgeCV instead of just calling the Ridge function. For RidgeCV we need to pass the array of \( \lambda \) values. +By inspecting the figure we can in turn determine which is the optimal regularization parameter. +This becomes however less functional in the long run. +

    + +









    + + +

    An alternative is to use the so-called grid search functionality +included with the library Scikit-Learn, as demonstrated for the same +example here. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Decide which values of lambda to use
    +nlambdas = 10
    +lambdas = np.logspace(-4, 2, nlambdas)
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    By default the grid search function includes cross validation with +five folds. The Scikit-Learn +documentation +contains more information on how to set the different parameters. +

    + +

    If we take out the random noise, running the above codes results in \( \lambda=0 \) yielding the best fit.

    + +









    + + +

    An alternative to the above manual grid set up, is to use a random +search where the parameters are tuned from a random distribution +(uniform below) for a fixed number of iterations. A model is +constructed and evaluated for each combination of chosen parameters. +We repeat the previous example but now with a random search. Note +that values of \( \lambda \) are now limited to be within \( x\in +[0,1] \). This domain may not be the most relevant one for the specific +case under study. +

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from sklearn.model_selection import train_test_split
    +from sklearn.linear_model import Ridge
    +from sklearn.model_selection import GridSearchCV
    +from scipy.stats import uniform as randuniform
    +from sklearn.model_selection import RandomizedSearchCV
    +
    +
    +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(2021)
    +
    +n = 100
    +x = np.random.rand(n)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    +
    +Maxpolydegree = 5
    +X = np.zeros((n,Maxpolydegree-1))
    +
    +for degree in range(1,Maxpolydegree): #No intercept column
    +    X[:,degree-1] = x**(degree)
    +
    +# We split the data in test and training data
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +param_grid = {'alpha': randuniform()}
    +# create and fit a ridge regression model, testing each alpha
    +model = Ridge()
    +gridsearch = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
    +gridsearch.fit(X_train, y_train)
    +print(gridsearch)
    +ypredictRidge = gridsearch.predict(X_test)
    +# summarize the results of the grid search
    +print(f"Best estimated lambda-value: {gridsearch.best_estimator_.alpha}")
    +print(f"MSE score: {MSE(y_test,ypredictRidge)}")
    +print(f"R2 score: {R2(y_test,ypredictRidge)}")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +









    Wisconsin Cancer Data

    @@ -1578,6 +1945,1060 @@ randomness. One such method is that of Stochastic Gradient Descent (SGD), see below.

    +









    +

    Revisiting our Logistic Regression case

    + +

    In our discussion on Logistic Regression we studied the +case of +two classes, with \( y_i \) either +\( 0 \) or \( 1 \). Furthermore we assumed also that we have only two +parameters \( \beta \) in our fitting, that is we +defined probabilities +

    + +$$ +\begin{align*} +p(y_i=1|x_i,\boldsymbol{\beta}) &= \frac{\exp{(\beta_0+\beta_1x_i)}}{1+\exp{(\beta_0+\beta_1x_i)}},\nonumber\\ +p(y_i=0|x_i,\boldsymbol{\beta}) &= 1 - p(y_i=1|x_i,\boldsymbol{\beta}), +\end{align*} +$$ + +

    where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in our case \( \beta_0 \) and \( \beta_1 \).

    + +









    +

    The equations to solve

    + +

    Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \) +elements \( y_i \), an \( n\times p \) matrix \( \boldsymbol{X} \) which contains the +\( x_i \) values and a vector \( \boldsymbol{p} \) of fitted probabilities +\( p(y_i\vert x_i,\boldsymbol{\beta}) \). We rewrote in a more compact form +the first derivative of the cost function as +

    + +$$ +\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = -\boldsymbol{X}^T\left(\boldsymbol{y}-\boldsymbol{p}\right). +$$ + +

    If we in addition define a diagonal matrix \( \boldsymbol{W} \) with elements +\( p(y_i\vert x_i,\boldsymbol{\beta})(1-p(y_i\vert x_i,\boldsymbol{\beta}) \), we can obtain a compact expression of the second derivative as +

    + +$$ +\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T} = \boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X}. +$$ + +

    This defines what is called the Hessian matrix.

    + +









    +

    Solving using Newton-Raphson's method

    + +

    If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.

    + +

    Our iterative scheme is then given by

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\frac{\partial^2 \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}\partial \boldsymbol{\beta}^T}\right)^{-1}_{\boldsymbol{\beta}^{\mathrm{old}}}\times \left(\frac{\partial \mathcal{C}(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}}\right)_{\boldsymbol{\beta}^{\mathrm{old}}}, +$$ + +

    or in matrix form as

    + +$$ +\boldsymbol{\beta}^{\mathrm{new}} = \boldsymbol{\beta}^{\mathrm{old}}-\left(\boldsymbol{X}^T\boldsymbol{W}\boldsymbol{X} \right)^{-1}\times \left(-\boldsymbol{X}^T(\boldsymbol{y}-\boldsymbol{p}) \right)_{\boldsymbol{\beta}^{\mathrm{old}}}. +$$ + +

    The right-hand side is computed with the old values of \( \beta \).

    + +

    If we can compute these matrices, in particular the Hessian, the above is often the easiest method to implement.

    + + +

    Convex functions

    + +

    Ideally we want our cost/loss function to be convex(concave).

    + +

    First we give the definition of a convex set: A set \( C \) in +\( \mathbb{R}^n \) is said to be convex if, for all \( x \) and \( y \) in \( C \) and +all \( t \in (0,1) \) , the point \( (1 − t)x + ty \) also belongs to +C. Geometrically this means that every point on the line segment +connecting \( x \) and \( y \) is in \( C \) as discussed below. +

    + +

    The convex subsets of \( \mathbb{R} \) are the intervals of +\( \mathbb{R} \). Examples of convex sets of \( \mathbb{R}^2 \) are the +regular polygons (triangles, rectangles, pentagons, etc...). +

    + +









    +

    Convex function

    + +

    Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if $$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$ for all \( x_1, x_2 \in X \) and for all \( t \in [0,1] \). If \( \leq \) is replaced with a strict inequaltiy in the definition, we demand \( x_1 \neq x_2 \) and \( t\in(0,1) \) then \( f \) is said to be strictly convex. For a single variable function, convexity means that if you draw a straight line connecting \( f(x_1) \) and \( f(x_2) \), the value of the function on the interval \( [x_1,x_2] \) is always below the line as illustrated below.

    + +









    +

    Conditions on convex functions

    + +

    In the following we state first and second-order conditions which +ensures convexity of a function \( f \). We write \( D_f \) to denote the +domain of \( f \), i.e the subset of \( R^n \) where \( f \) is defined. For more +details and proofs we refer to: S. Boyd and L. Vandenberghe. Convex Optimization. Cambridge University Press. +

    + +
    +First order condition +

    +

    Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for +all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \) +is a convex set and $$f(y) \geq f(x) + \nabla f(x)^T (y-x) $$ holds +for all \( x,y \in D_f \). This condition means that for a convex function +the first order Taylor expansion (right hand side above) at any point +a global under estimator of the function. To convince yourself you can +make a drawing of \( f(x) = x^2+1 \) and draw the tangent line to \( f(x) \) and +note that it is always below the graph. +

    +
    + + +
    +Second order condition +

    +

    Assume that \( f \) is twice +differentiable, i.e the Hessian matrix exists at each point in +\( D_f \). Then \( f \) is convex if and only if \( D_f \) is a convex set and its +Hessian is positive semi-definite for all \( x\in D_f \). For a +single-variable function this reduces to \( f''(x) \geq 0 \). Geometrically this means that \( f \) has nonnegative curvature +everywhere. +

    +
    + + +

    This condition is particularly useful since it gives us an procedure for determining if the function under consideration is convex, apart from using the definition.

    + +









    +

    More on convex functions

    + +

    The next result is of great importance to us and the reason why we are +going on about convex functions. In machine learning we frequently +have to minimize a loss/cost function in order to find the best +parameters for the model we are considering. +

    + +

    Ideally we want the +global minimum (for high-dimensional models it is hard to know +if we have local or global minimum). However, if the cost/loss function +is convex the following result provides invaluable information: +

    + +
    +Any minimum is global for convex functions +

    +

    Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \) +is minimal, where \( f \) is convex and differentiable. Then, any point +\( x^* \) that satisfies \( \nabla f(x^*) = 0 \) is a global minimum. +

    +
    + + +

    This result means that if we know that the cost/loss function is convex and we are able to find a minimum, we are guaranteed that it is a global minimum.

    + +









    +

    Some simple problems

    + +
      +
    1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
    2. +
    3. Using the second order condition show that the following functions are convex on the specified domain.
    4. +
        +
      • \( f(x) = e^x \) is convex for \( x \in \mathbb{R} \).
      • +
      • \( g(x) = -\ln(x) \) is convex for \( x \in (0,\infty) \).
      • +
      +
    5. Let \( f(x) = x^2 \) and \( g(x) = e^x \). Show that \( f(g(x)) \) and \( g(f(x)) \) is convex for \( x \in \mathbb{R} \). Also show that if \( f(x) \) is any convex function than \( h(x) = e^{f(x)} \) is convex.
    6. +
    7. A norm is any function that satisfy the following properties
    8. +
        +
      • \( f(\alpha x) = |\alpha| f(x) \) for all \( \alpha \in \mathbb{R} \).
      • +
      • \( f(x+y) \leq f(x) + f(y) \)
      • +
      • \( f(x) \leq 0 \) for all \( x \in \mathbb{R}^n \) with equality if and only if \( x = 0 \)
      • +
      +
    +

    Using the definition of convexity, try to show that a function satisfying the properties above is convex (the third condition is not needed to show this).

    + +









    +

    Standard steepest descent

    + +

    Before we proceed, we would like to discuss the approach called the +standard Steepest descent (different from the above steepest descent discussion), which again leads to us having to be able +to compute a matrix. It belongs to the class of Conjugate Gradient methods (CG). +

    + +The success of the CG method +

    for finding solutions of non-linear problems is based on the theory +of conjugate gradients for linear systems of equations. It belongs to +the class of iterative methods for solving problems from linear +algebra of the type +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}. +\end{equation*} +$$ + +

    In the iterative process we end up with a problem like

    + +$$ +\begin{equation*} + \boldsymbol{r}= \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}, +\end{equation*} +$$ + +

    where \( \boldsymbol{r} \) is the so-called residual or error in the iterative process.

    + +

    When we have found the exact solution, \( \boldsymbol{r}=0 \).

    + +









    +

    Gradient method

    + +

    The residual is zero when we reach the minimum of the quadratic equation

    +$$ +\begin{equation*} + P(\boldsymbol{x})=\frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T\boldsymbol{b}, +\end{equation*} +$$ + +

    with the constraint that the matrix \( \boldsymbol{A} \) is positive definite and +symmetric. This defines also the Hessian and we want it to be positive definite. +

    + +









    +

    Steepest descent method

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ + +

    or consider the system

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ + +

    instead.

    + +









    +

    Steepest descent method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ + +

    This suggests taking the first basis vector \( \boldsymbol{r}_1 \) (see below for definition) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +

    +
    + + +









    +

    Final expressions

    +
    + +

    +

    We can compute the residual iteratively as

    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ + +

    which equals

    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{r}_k), + \end{equation*} +$$ + +

    or

    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{r}_k, + \end{equation*} +$$ + +

    which gives

    + +$$ +\alpha_k = \frac{\boldsymbol{r}_k^T\boldsymbol{r}_k}{\boldsymbol{r}_k^T\boldsymbol{A}\boldsymbol{r}_k} +$$ + +

    leading to the iterative scheme

    +$$ +\begin{equation*} +\boldsymbol{x}_{k+1}=\boldsymbol{x}_k-\alpha_k\boldsymbol{r}_{k}, + \end{equation*} +$$ +
    + + +









    +

    Steepest descent example

    + + + +
    +
    +
    +
    +
    +
    import numpy as np
    +import numpy.linalg as la
    +
    +import scipy.optimize as sopt
    +
    +import matplotlib.pyplot as pt
    +from mpl_toolkits.mplot3d import axes3d
    +
    +def f(x):
    +    return x[0]**2 + 3.0*x[1]**2
    +
    +def df(x):
    +    return np.array([2*x[0], 6*x[1]])
    +
    +fig = pt.figure()
    +ax = fig.gca(projection="3d")
    +
    +xmesh, ymesh = np.mgrid[-3:3:50j,-3:3:50j]
    +fmesh = f(np.array([xmesh, ymesh]))
    +ax.plot_surface(xmesh, ymesh, fmesh)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    And then as countor plot

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh)
    +guesses = [np.array([2, 2./5])]
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Find guesses

    + + +
    +
    +
    +
    +
    +
    x = guesses[-1]
    +s = -df(x)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Run it!

    + + +
    +
    +
    +
    +
    +
    def f1d(alpha):
    +    return f(x + alpha*s)
    +
    +alpha_opt = sopt.golden(f1d)
    +next_guess = x + alpha_opt * s
    +guesses.append(next_guess)
    +print(next_guess)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    What happened?

    + + +
    +
    +
    +
    +
    +
    pt.axis("equal")
    +pt.contour(xmesh, ymesh, fmesh, 50)
    +it_array = np.array(guesses)
    +pt.plot(it_array.T[0], it_array.T[1], "x-")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Note that we did only one iteration here. We can easily add more using our previous guesses.

    + +









    +

    Conjugate gradient method

    +
    + +

    +

    In the CG method we define so-called conjugate directions and two vectors +\( \boldsymbol{s} \) and \( \boldsymbol{t} \) +are said to be +conjugate if +

    +$$ +\begin{equation*} +\boldsymbol{s}^T\boldsymbol{A}\boldsymbol{t}= 0. +\end{equation*} +$$ + +

    The philosophy of the CG method is to perform searches in various conjugate directions +of our vectors \( \boldsymbol{x}_i \) obeying the above criterion, namely +

    +$$ +\begin{equation*} +\boldsymbol{x}_i^T\boldsymbol{A}\boldsymbol{x}_j= 0. +\end{equation*} +$$ + +

    Two vectors are conjugate if they are orthogonal with respect to +this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s} \) is conjugate to \( \boldsymbol{t} \), then \( \boldsymbol{t} \) is conjugate to \( \boldsymbol{s} \). +

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    An example is given by the eigenvectors of the matrix

    +$$ +\begin{equation*} +\boldsymbol{v}_i^T\boldsymbol{A}\boldsymbol{v}_j= \lambda\boldsymbol{v}_i^T\boldsymbol{v}_j, +\end{equation*} +$$ + +

    which is zero unless \( i=j \).

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    Assume now that we have a symmetric positive-definite matrix \( \boldsymbol{A} \) of size +\( n\times n \). At each iteration \( i+1 \) we obtain the conjugate direction of a vector +

    +$$ +\begin{equation*} +\boldsymbol{x}_{i+1}=\boldsymbol{x}_{i}+\alpha_i\boldsymbol{p}_{i}. +\end{equation*} +$$ + +

    We assume that \( \boldsymbol{p}_{i} \) is a sequence of \( n \) mutually conjugate directions. +Then the \( \boldsymbol{p}_{i} \) form a basis of \( R^n \) and we can expand the solution +$ \boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}$ in this basis, namely +

    + +$$ +\begin{equation*} + \boldsymbol{x} = \sum^{n}_{i=1} \alpha_i \boldsymbol{p}_i. +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    The coefficients are given by

    +$$ +\begin{equation*} + \mathbf{A}\mathbf{x} = \sum^{n}_{i=1} \alpha_i \mathbf{A} \mathbf{p}_i = \mathbf{b}. +\end{equation*} +$$ + +

    Multiplying with \( \boldsymbol{p}_k^T \) from the left gives

    + +$$ +\begin{equation*} + \boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{x} = \sum^{n}_{i=1} \alpha_i\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{p}_i= \boldsymbol{p}_k^T \boldsymbol{b}, +\end{equation*} +$$ + +

    and we can define the coefficients \( \alpha_k \) as

    + +$$ +\begin{equation*} + \alpha_k = \frac{\boldsymbol{p}_k^T \boldsymbol{b}}{\boldsymbol{p}_k^T \boldsymbol{A} \boldsymbol{p}_k} +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method and iterations

    +
    + +

    + +

    If we choose the conjugate vectors \( \boldsymbol{p}_k \) carefully, +then we may not need all of them to obtain a good approximation to the solution +\( \boldsymbol{x} \). +We want to regard the conjugate gradient method as an iterative method. +This will us to solve systems where \( n \) is so large that the direct +method would take too much time. +

    + +

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). +We can assume without loss of generality that +

    +$$ +\begin{equation*} +\boldsymbol{x}_0=0, +\end{equation*} +$$ + +

    or consider the system

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{z} = \boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_0, +\end{equation*} +$$ + +

    instead.

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    One can show that the solution \( \boldsymbol{x} \) is also the unique minimizer of the quadratic form

    +$$ +\begin{equation*} + f(\boldsymbol{x}) = \frac{1}{2}\boldsymbol{x}^T\boldsymbol{A}\boldsymbol{x} - \boldsymbol{x}^T \boldsymbol{x} , \quad \boldsymbol{x}\in\mathbf{R}^n. +\end{equation*} +$$ + +

    This suggests taking the first basis vector \( \boldsymbol{p}_1 \) +to be the gradient of \( f \) at \( \boldsymbol{x}=\boldsymbol{x}_0 \), +which equals +

    +$$ +\begin{equation*} +\boldsymbol{A}\boldsymbol{x}_0-\boldsymbol{b}, +\end{equation*} +$$ + +

    and +\( \boldsymbol{x}_0=0 \) it is equal \( -\boldsymbol{b} \). +The other vectors in the basis will be conjugate to the gradient, +hence the name conjugate gradient method. +

    +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    Let \( \boldsymbol{r}_k \) be the residual at the \( k \)-th step:

    +$$ +\begin{equation*} +\boldsymbol{r}_k=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k. +\end{equation*} +$$ + +

    Note that \( \boldsymbol{r}_k \) is the negative gradient of \( f \) at +\( \boldsymbol{x}=\boldsymbol{x}_k \), +so the gradient descent method would be to move in the direction \( \boldsymbol{r}_k \). +Here, we insist that the directions \( \boldsymbol{p}_k \) are conjugate to each other, +so we take the direction closest to the gradient \( \boldsymbol{r}_k \) +under the conjugacy constraint. +This gives the following expression +

    +$$ +\begin{equation*} +\boldsymbol{p}_{k+1}=\boldsymbol{r}_k-\frac{\boldsymbol{p}_k^T \boldsymbol{A}\boldsymbol{r}_k}{\boldsymbol{p}_k^T\boldsymbol{A}\boldsymbol{p}_k} \boldsymbol{p}_k. +\end{equation*} +$$ +
    + + +









    +

    Conjugate gradient method

    +
    + +

    +

    We can also compute the residual iteratively as

    +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_{k+1}, + \end{equation*} +$$ + +

    which equals

    +$$ +\begin{equation*} +\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}_k+\alpha_k\boldsymbol{p}_k), + \end{equation*} +$$ + +

    or

    +$$ +\begin{equation*} +(\boldsymbol{b}-\boldsymbol{A}\boldsymbol{x}_k)-\alpha_k\boldsymbol{A}\boldsymbol{p}_k, + \end{equation*} +$$ + +

    which gives

    + +$$ +\begin{equation*} +\boldsymbol{r}_{k+1}=\boldsymbol{r}_k-\boldsymbol{A}\boldsymbol{p}_{k}, + \end{equation*} +$$ +
    + + + +

    Revisiting our first homework

    + +

    We will use linear regression as a case study for the gradient descent +methods. Linear regression is a great test case for the gradient +descent methods discussed in the lectures since it has several +desirable properties such as: +

    + +
      +
    1. An analytical solution (recall homework set 1).
    2. +
    3. The gradient can be computed analytically.
    4. +
    5. The cost function is convex which guarantees that gradient descent converges for small enough learning rates
    6. +
    +

    We revisit an example similar to what we had in the first homework set. We had a function of the type

    + + + +
    +
    +
    +
    +
    +
    x = 2*np.random.rand(m,1)
    +y = 4+3*x+np.random.randn(m,1)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    with \( x_i \in [0,1] \) is chosen randomly using a uniform distribution. Additionally we have a stochastic noise chosen according to a normal distribution \( \cal {N}(0,1) \). +The linear regression model is given by +

    +$$ +h_\beta(x) = \boldsymbol{y} = \beta_0 + \beta_1 x, +$$ + +

    such that

    +$$ +\boldsymbol{y}_i = \beta_0 + \beta_1 x_i. +$$ + + + +

    Gradient descent example

    + +

    Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)

    + +

    It is convenient to write \( \mathbf{\boldsymbol{y}} = X\beta \) where \( X \in \mathbb{R}^{100 \times 2} \) is the design matrix given by (we keep the intercept here)

    +$$ +X \equiv \begin{bmatrix} +1 & x_1 \\ +\vdots & \vdots \\ +1 & x_{100} & \\ +\end{bmatrix}. +$$ + +

    The cost/loss/risk function is given by (

    +$$ +C(\beta) = \frac{1}{n}||X\beta-\mathbf{y}||_{2}^{2} = \frac{1}{n}\sum_{i=1}^{100}\left[ (\beta_0 + \beta_1 x_i)^2 - 2 y_i (\beta_0 + \beta_1 x_i) + y_i^2\right] +$$ + +

    and we want to find \( \beta \) such that \( C(\beta) \) is minimized.

    + +









    +

    The derivative of the cost/loss function

    + +

    Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as

    +$$ +\nabla_{\beta} C(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} = \frac{2}{n}X^T(X\beta - \mathbf{y}), +$$ + +

    where \( X \) is the design matrix defined above.

    + +









    +

    The Hessian matrix

    +

    The Hessian matrix of \( C(\beta) \) is given by

    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X. +$$ + +

    This result implies that \( C(\beta) \) is a convex function since the matrix \( X^T X \) always is positive semi-definite.

    + +









    +

    Simple program

    + +

    We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to

    +$$ +\beta_{k+1} = \beta_k - \gamma \nabla_\beta C(\beta_k), \ k=0,1,\cdots +$$ + +

    We can use the expression we computed for the gradient and let use a +\( \beta_0 \) be chosen randomly and let \( \gamma = 0.001 \). Stop iterating +when \( ||\nabla_\beta C(\beta_k) || \leq \epsilon = 10^{-8} \). Note that the code below does not include the latter stop criterion. +

    + +

    And finally we can compare our solution for \( \beta \) with the analytic result given by +\( \beta= (X^TX)^{-1} X^T \mathbf{y} \). +

    + +









    +

    Gradient Descent Example

    + +

    Here our simple example

    + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +# Hessian matrix
    +H = (2.0/n)* X.T @ X
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y
    +print(beta_linreg)
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 1000
    +
    +for iter in range(Niterations):
    +    gradient = (2.0/n)*X.T @ (X @ beta-y)
    +    beta -= eta*gradient
    +
    +print(beta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(beta)
    +ypredict2 = xbnew.dot(beta_linreg)
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(xnew, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +









    +

    And a corresponding example using scikit-learn

    + + + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +beta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y)
    +print(beta_linreg)
    +sgdreg = SGDRegressor(max_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + +

    Gradient descent and Ridge

    + +

    We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),

    +$$ +C_{\text{ridge}}(\beta) = \frac{1}{n}||X\beta -\mathbf{y}||^2 + \lambda ||\beta||^2, \ \lambda \geq 0. +$$ + +

    In order to minimize \( C_{\text{ridge}}(\beta) \) using GD we adjust the gradient as follows

    +$$ +\nabla_\beta C_{\text{ridge}}(\beta) = \frac{2}{n}\begin{bmatrix} \sum_{i=1}^{100} \left(\beta_0+\beta_1x_i-y_i\right) \\ +\sum_{i=1}^{100}\left( x_i (\beta_0+\beta_1x_i)-y_ix_i\right) \\ +\end{bmatrix} + 2\lambda\begin{bmatrix} \beta_0 \\ \beta_1\end{bmatrix} = 2 (\frac{1}{n}X^T(X\beta - \mathbf{y})+\lambda \beta). +$$ + +

    We can easily extend our program to minimize \( C_{\text{ridge}}(\beta) \) using gradient descent and compare with the analytical solution given by

    +$$ +\beta_{\text{ridge}} = \left(X^T X + n\lambda I_{2 \times 2} \right)^{-1} X^T \mathbf{y}. +$$ + + +









    +

    The Hessian matrix for Ridge Regression

    +

    The Hessian matrix of Ridge Regression for our simple example is given by

    +$$ +\boldsymbol{H} \equiv \begin{bmatrix} +\frac{\partial^2 C(\beta)}{\partial \beta_0^2} & \frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} \\ +\frac{\partial^2 C(\beta)}{\partial \beta_0 \partial \beta_1} & \frac{\partial^2 C(\beta)}{\partial \beta_1^2} & \\ +\end{bmatrix} = \frac{2}{n}X^T X+2\lambda\boldsymbol{I}. +$$ + +

    This implies that the Hessian matrix is positive definite, hence the stationary point is a +minimum. +Note that the Ridge cost function is convex being a sum of two convex +functions. Therefore, the stationary point is a global +minimum of this function. +

    + +









    +

    Program example for gradient descent with Ridge Regression

    + + +
    +
    +
    +
    +
    +
    from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from mpl_toolkits.mplot3d import Axes3D
    +from matplotlib import cm
    +from matplotlib.ticker import LinearLocator, FormatStrFormatter
    +import sys
    +
    +# the number of datapoints
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x]
    +XT_X = X.T @ X
    +
    +#Ridge parameter lambda
    +lmbda  = 0.001
    +Id = n*lmbda* np.eye(XT_X.shape[0])
    +
    +# Hessian matrix
    +H = (2.0/n)* XT_X+2*lmbda* np.eye(XT_X.shape[0])
    +# Get the eigenvalues
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    +
    +
    +beta_linreg = np.linalg.inv(XT_X+Id) @ X.T @ y
    +print(beta_linreg)
    +# Start plain gradient descent
    +beta = np.random.randn(2,1)
    +
    +eta = 1.0/np.max(EigValues)
    +Niterations = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/n*X.T @ (X @ (beta)-y)+2*lmbda*beta
    +    beta -= eta*gradients
    +
    +print(beta)
    +ypredict = X @ beta
    +ypredict2 = X @ beta_linreg
    +plt.plot(x, ypredict, "r-")
    +plt.plot(x, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Gradient descent example for Ridge')
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +









    +

    Using gradient descent methods, limitations

    + +
      +
    • Gradient descent (GD) finds local minima of our function. Since the GD algorithm is deterministic, if it converges, it will converge to a local minimum of our cost/loss/risk function. Because in ML we are often dealing with extremely rugged landscapes with many local minima, this can lead to poor performance.
    • +
    • GD is sensitive to initial conditions. One consequence of the local nature of GD is that initial conditions matter. Depending on where one starts, one will end up at a different local minima. Therefore, it is very important to think about how one initializes the training process. This is true for GD as well as more complicated variants of GD.
    • +
    • Gradients are computationally expensive to calculate for large datasets. In many cases in statistics and ML, the cost/loss/risk function is a sum of terms, with one term for each data point. For example, in linear regression, \( E \propto \sum_{i=1}^n (y_i - \mathbf{w}^T\cdot\mathbf{x}_i)^2 \); for logistic regression, the square error is replaced by the cross entropy. To calculate the gradient we have to sum over all \( n \) data points. Doing this at every GD step becomes extremely computationally expensive. An ingenious solution to this, is to calculate the gradients using small subsets of the data called "mini batches". This has the added benefit of introducing stochasticity into our algorithm.
    • +
    • GD is very sensitive to choices of learning rates. GD is extremely sensitive to the choice of learning rates. If the learning rate is very small, the training process take an extremely long time. For larger learning rates, GD can diverge and give poor results. Furthermore, depending on what the local landscape looks like, we have to modify the learning rates to ensure convergence. Ideally, we would adaptively choose the learning rates to match the landscape.
    • +
    • GD treats all directions in parameter space uniformly. Another major drawback of GD is that unlike Newton's method, the learning rate for GD is the same in all directions in parameter space. For this reason, the maximum learning rate is set by the behavior of the steepest direction and this can significantly slow down training. Ideally, we would like to take large steps in flat directions and small steps in steep directions. Since we are exploring rugged landscapes where curvatures change, this requires us to keep track of not only the gradient but second derivatives. The ideal scenario would be to calculate the Hessian but this proves to be too computationally expensive.
    • +
    • GD can take exponential time to escape saddle points, even with random initialization. As we mentioned, GD is extremely sensitive to initial condition since it determines the particular local minimum GD would eventually reach. However, even with a good initialization scheme, through the introduction of randomness, GD can still take exponential time to escape saddle points.
    • +
    +









    +

    Challenge yourself this weekend

    + +

    Write a code which implements gradient descent for a logistic regression example.

    +
    © 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license diff --git a/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz b/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz index ba2f69d5f5267714da93f4f5b72adeef9f6d03c9..58c236f87bc3ed9018ca2923a38d37f97ac046cd 100644 GIT binary patch literal 193 zcmV;y06za8iwFSIM=fIj1MSaC3c@fD2H>uHia9|^nxu6r*o6y0#0#V}wXrs-Ns9LN z_5r$5+!PV=ZGMIshM7aQ-t4l--CeL4git~$jF~2EN)*ra1Y-u65=>%B(wG3kgvBfX zwA@KAopsy{r!>`BC@a*vxnZm1TYQ-;MYxK$R#zx_>FAC|TR{Rn+Mjs8YZ500c8PD@P?`sb{&J1h-2mk