diff --git a/doc/pub/week37/html/._week37-bs000.html b/doc/pub/week37/html/._week37-bs000.html index d3cd07a53..e3771e97a 100644 --- a/doc/pub/week37/html/._week37-bs000.html +++ b/doc/pub/week37/html/._week37-bs000.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -335,7 +328,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs001.html b/doc/pub/week37/html/._week37-bs001.html index 17b37a655..3512f1e2a 100644 --- a/doc/pub/week37/html/._week37-bs001.html +++ b/doc/pub/week37/html/._week37-bs001.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -338,7 +331,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs002.html b/doc/pub/week37/html/._week37-bs002.html index e1a4c4742..b132888f7 100644 --- a/doc/pub/week37/html/._week37-bs002.html +++ b/doc/pub/week37/html/._week37-bs002.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -309,7 +302,7 @@ MathJax.Hub.Config({
  • 11
  • 12
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs003.html b/doc/pub/week37/html/._week37-bs003.html index 87c59672a..551fd736a 100644 --- a/doc/pub/week37/html/._week37-bs003.html +++ b/doc/pub/week37/html/._week37-bs003.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -352,7 +345,7 @@ row number \( i \) and perform a sum over all values \( p \).
  • 12
  • 13
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs004.html b/doc/pub/week37/html/._week37-bs004.html index 700516db2..066f99576 100644 --- a/doc/pub/week37/html/._week37-bs004.html +++ b/doc/pub/week37/html/._week37-bs004.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -327,7 +320,7 @@ $$
  • 13
  • 14
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs005.html b/doc/pub/week37/html/._week37-bs005.html index 0d9960f8c..e010be5c5 100644 --- a/doc/pub/week37/html/._week37-bs005.html +++ b/doc/pub/week37/html/._week37-bs005.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -343,7 +336,7 @@ mean value \( \boldsymbol{X}\boldsymbol{\beta} \) and variance \( \sigma^2 \) (n
  • 14
  • 15
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs006.html b/doc/pub/week37/html/._week37-bs006.html index 0b97b865f..308ecbe5c 100644 --- a/doc/pub/week37/html/._week37-bs006.html +++ b/doc/pub/week37/html/._week37-bs006.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -390,7 +383,7 @@ This means the variance we obtain with the standard OLS will always for \( \lamb
  • 15
  • 16
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs007.html b/doc/pub/week37/html/._week37-bs007.html index 9c3bbd5cc..d9c3f8dbe 100644 --- a/doc/pub/week37/html/._week37-bs007.html +++ b/doc/pub/week37/html/._week37-bs007.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -314,7 +307,7 @@ MathJax.Hub.Config({
  • 16
  • 17
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs008.html b/doc/pub/week37/html/._week37-bs008.html index be9516864..2d8447080 100644 --- a/doc/pub/week37/html/._week37-bs008.html +++ b/doc/pub/week37/html/._week37-bs008.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -335,7 +328,7 @@ $$
  • 17
  • 18
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs009.html b/doc/pub/week37/html/._week37-bs009.html index f1f99c14f..7d9e9ace0 100644 --- a/doc/pub/week37/html/._week37-bs009.html +++ b/doc/pub/week37/html/._week37-bs009.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -347,7 +340,7 @@ $$
  • 18
  • 19
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs010.html b/doc/pub/week37/html/._week37-bs010.html index c7b7097a6..b570822b6 100644 --- a/doc/pub/week37/html/._week37-bs010.html +++ b/doc/pub/week37/html/._week37-bs010.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -342,7 +335,7 @@ is equivalent to the maximization/minimization of the function itself.
  • 19
  • 20
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs011.html b/doc/pub/week37/html/._week37-bs011.html index 483376afb..3eaafe8e9 100644 --- a/doc/pub/week37/html/._week37-bs011.html +++ b/doc/pub/week37/html/._week37-bs011.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -341,7 +334,7 @@ $$
  • 20
  • 21
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs012.html b/doc/pub/week37/html/._week37-bs012.html index a71c57633..c015911a9 100644 --- a/doc/pub/week37/html/._week37-bs012.html +++ b/doc/pub/week37/html/._week37-bs012.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -351,7 +344,7 @@ $$
  • 21
  • 22
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs013.html b/doc/pub/week37/html/._week37-bs013.html index cd1a20a82..ea2a5ef7e 100644 --- a/doc/pub/week37/html/._week37-bs013.html +++ b/doc/pub/week37/html/._week37-bs013.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -328,7 +321,7 @@ $$
  • 22
  • 23
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs014.html b/doc/pub/week37/html/._week37-bs014.html index 6a5857096..2ad30cc12 100644 --- a/doc/pub/week37/html/._week37-bs014.html +++ b/doc/pub/week37/html/._week37-bs014.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -328,7 +321,7 @@ $$
  • 23
  • 24
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs015.html b/doc/pub/week37/html/._week37-bs015.html index 6c5bfd64b..735e52977 100644 --- a/doc/pub/week37/html/._week37-bs015.html +++ b/doc/pub/week37/html/._week37-bs015.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -330,7 +323,7 @@ $$
  • 24
  • 25
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs016.html b/doc/pub/week37/html/._week37-bs016.html index 64a76fc7f..18e4be95f 100644 --- a/doc/pub/week37/html/._week37-bs016.html +++ b/doc/pub/week37/html/._week37-bs016.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -327,7 +320,7 @@ necesseraly normalized and is normally called the likelihood function.
  • 25
  • 26
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs017.html b/doc/pub/week37/html/._week37-bs017.html index d2074ad95..37129607a 100644 --- a/doc/pub/week37/html/._week37-bs017.html +++ b/doc/pub/week37/html/._week37-bs017.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -337,7 +330,7 @@ It is however not correct, as the following Bayesian analysis shows.
  • 26
  • 27
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs018.html b/doc/pub/week37/html/._week37-bs018.html index 532959cc6..b9e639345 100644 --- a/doc/pub/week37/html/._week37-bs018.html +++ b/doc/pub/week37/html/._week37-bs018.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -338,7 +331,7 @@ $$
  • 27
  • 28
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs019.html b/doc/pub/week37/html/._week37-bs019.html index 394cb786e..c3a711988 100644 --- a/doc/pub/week37/html/._week37-bs019.html +++ b/doc/pub/week37/html/._week37-bs019.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -342,7 +335,7 @@ $$
  • 28
  • 29
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs020.html b/doc/pub/week37/html/._week37-bs020.html index 22175cf12..a78a6728f 100644 --- a/doc/pub/week37/html/._week37-bs020.html +++ b/doc/pub/week37/html/._week37-bs020.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -351,7 +344,7 @@ $$
  • 29
  • 30
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs021.html b/doc/pub/week37/html/._week37-bs021.html index 7dc25c318..4fe568dcc 100644 --- a/doc/pub/week37/html/._week37-bs021.html +++ b/doc/pub/week37/html/._week37-bs021.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -345,7 +338,7 @@ $$
  • 30
  • 31
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs022.html b/doc/pub/week37/html/._week37-bs022.html index d1121de7c..1a71eb132 100644 --- a/doc/pub/week37/html/._week37-bs022.html +++ b/doc/pub/week37/html/._week37-bs022.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,103 +283,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Test Function for what happens with OLS, Ridge and Lasso

    +

    Why resampling methods

    -

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

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

    - -

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

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

    How can we understand this?

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

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

    @@ -413,7 +320,7 @@ plt.show()

  • 31
  • 32
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs023.html b/doc/pub/week37/html/._week37-bs023.html index 620398a84..97e3a7f5a 100644 --- a/doc/pub/week37/html/._week37-bs023.html +++ b/doc/pub/week37/html/._week37-bs023.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,88 +283,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Rerunning the above code

    - -

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

    Resampling methods

    +
    +
    + +

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

    -

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

    Two resampling methods are often used in Machine Learning analyses,

    +
      +
    1. The bootstrap method
    2. +
    3. and Cross-Validation
    4. +
    +

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

    - -

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

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -from IPython.display import display
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    -
    -# Make data set.
    -n = 1000
    -x = np.random.rand(n)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    -
    -Maxpolydegree = 5
    -X = np.zeros((len(x),Maxpolydegree))
    -X[:,0] = 1.0
    -
    -for polydegree in range(1, Maxpolydegree+1):
    -    for degree in range(polydegree):
    -        X[:,degree] = x**(degree)
    -
    -
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# Decide which values of lambda to use
    -nlambdas = 5
    -lambdas = np.logspace(-3, 2, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    # Make the fit using Ridge only
    -    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    -    RegRidge.fit(X_train,y_train)
    -    # and then make the prediction
    -    ypredictRidge = RegRidge.predict(X_test)
    -    Coeffs = np.array(RegRidge.coef_)
    -    BetaValues = pd.DataFrame(Coeffs)
    -    BetaValues.columns = ['beta']
    -    display(BetaValues)    
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    @@ -400,7 +336,7 @@ lambdas = np.32
  • 33
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs024.html b/doc/pub/week37/html/._week37-bs024.html index 9568674fe..4c6442272 100644 --- a/doc/pub/week37/html/._week37-bs024.html +++ b/doc/pub/week37/html/._week37-bs024.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,17 +283,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Why resampling methods

    +

    Resampling approaches can be computationally expensive

    +
    +
    + -

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

    Resampling approaches can be computationally expensive, because they +involve fitting the same statistical method multiple times using +different subsets of the training data. However, due to recent +advances in computing power, the computational requirements of +resampling methods generally are not prohibitive. In this chapter, we +discuss two of the most commonly used resampling methods, +cross-validation and the bootstrap. Both methods are important tools +in the practical application of many statistical learning +procedures. For example, cross-validation can be used to estimate the +test error associated with a given statistical learning method in +order to evaluate its performance, or to select the appropriate level +of flexibility. The process of evaluating a model’s performance is +known as model assessment, whereas the process of selecting the proper +level of flexibility for a model is known as model selection. The +bootstrap is widely used.

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

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

    +
    +
    +

    @@ -327,7 +333,7 @@ our regression analysis. In what follows we will

  • 33
  • 34
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs025.html b/doc/pub/week37/html/._week37-bs025.html index 161d418c6..dc4d403c5 100644 --- a/doc/pub/week37/html/._week37-bs025.html +++ b/doc/pub/week37/html/._week37-bs025.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,33 +283,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods

    +

    Why resampling methods ?

    -

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

    -

    Two resampling methods are often used in Machine Learning analyses,

    -
      -
    1. The bootstrap method
    2. -
    3. and Cross-Validation
    4. -
    -

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

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

    @@ -343,7 +322,7 @@ cross-validation and the bootstrap method.

  • 34
  • 35
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs026.html b/doc/pub/week37/html/._week37-bs026.html index 80ab4d82a..61f46a9a9 100644 --- a/doc/pub/week37/html/._week37-bs026.html +++ b/doc/pub/week37/html/._week37-bs026.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,30 +283,23 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling approaches can be computationally expensive

    +

    Statistical analysis

    -

    Resampling approaches can be computationally expensive, because they -involve fitting the same statistical method multiple times using -different subsets of the training data. However, due to recent -advances in computing power, the computational requirements of -resampling methods generally are not prohibitive. In this chapter, we -discuss two of the most commonly used resampling methods, -cross-validation and the bootstrap. Both methods are important tools -in the practical application of many statistical learning -procedures. For example, cross-validation can be used to estimate the -test error associated with a given statistical learning method in -order to evaluate its performance, or to select the appropriate level -of flexibility. The process of evaluating a model’s performance is -known as model assessment, whereas the process of selecting the proper -level of flexibility for a model is known as model selection. The -bootstrap is widely used. -

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

    @@ -340,7 +326,7 @@ bootstrap is widely used.

  • 35
  • 36
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs027.html b/doc/pub/week37/html/._week37-bs027.html index 95e539119..9198ae859 100644 --- a/doc/pub/week37/html/._week37-bs027.html +++ b/doc/pub/week37/html/._week37-bs027.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,19 +283,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Why resampling methods ?

    -
    -
    - +

    Resampling methods

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

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

    + +

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

    + +

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

    +
      +
    1. prediction error or simply the test error \( \mathrm{Err_{Test}} \), where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the
    2. +
    3. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    4. +
    +

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

    @@ -329,7 +333,7 @@ MathJax.Hub.Config({

  • 36
  • 37
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs028.html b/doc/pub/week37/html/._week37-bs028.html index 6770abaca..dd893fd08 100644 --- a/doc/pub/week37/html/._week37-bs028.html +++ b/doc/pub/week37/html/._week37-bs028.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,23 +283,28 @@ MathJax.Hub.Config({

     

     

     

    -

    Statistical analysis

    +

    Resampling methods: Bootstrap

    +

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

    +
      +
    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. +
    3. Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small.
    4. +
    5. It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.
    6. +
    7. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).
    8. +
    +
    +
    -
      -
    • As in other experiments, many numerical experiments have two classes of errors:
    • -
        -
      • Statistical errors
      • -
      • Systematical errors
      • -
      -
    • Statistical errors can be estimated using standard tools from statistics
    • -
    • Systematical errors are method specific and must be treated differently from case to case.
    • -
    -
    -
    - + +

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

    + +

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

    @@ -333,7 +331,7 @@ MathJax.Hub.Config({

  • 37
  • 38
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs029.html b/doc/pub/week37/html/._week37-bs029.html index a99d0ea26..9fd0db0fb 100644 --- a/doc/pub/week37/html/._week37-bs029.html +++ b/doc/pub/week37/html/._week37-bs029.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,30 +283,23 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods

    +

    The Central Limit Theorem

    -

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

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

    -

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

    +

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

    +$$ + z=\frac{x_1+x_2+\dots+x_m}{m}, +$$ -

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

    -
      -
    1. prediction error or simply the test error \( \mathrm{Err_{Test}} \), where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the
    2. -
    3. training error \( \mathrm{Err_{Train}} \), which is the average loss over the training data.
    4. -
    -

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

    +

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

    @@ -340,7 +326,7 @@ training error reaches a saturation.

  • 38
  • 39
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs030.html b/doc/pub/week37/html/._week37-bs030.html index 62f42e86b..9f04ef298 100644 --- a/doc/pub/week37/html/._week37-bs030.html +++ b/doc/pub/week37/html/._week37-bs030.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,28 +283,23 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods: Bootstrap

    -
    -
    - -

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

    Finding the Limit

    + +

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

    -
      -
    1. The bootstrap is quite general, although there are some cases in which it fails.
    2. -
    3. Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small.
    4. -
    5. It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.
    6. -
    7. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).
    8. -
    -
    -
    +$$ + \tilde{p}(z)=\int dx_1p(x_1)\int dx_2p(x_2)\dots\int dx_mp(x_m) + \delta(z-\frac{x_1+x_2+\dots+x_m}{m}), +$$ - -

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

    - -

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

    +

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

    @@ -338,7 +326,7 @@ advantages:

  • 39
  • 40
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs031.html b/doc/pub/week37/html/._week37-bs031.html index a1fbbe2f2..778b85b7a 100644 --- a/doc/pub/week37/html/._week37-bs031.html +++ b/doc/pub/week37/html/._week37-bs031.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,23 +283,32 @@ MathJax.Hub.Config({

     

     

     

    -

    The Central Limit Theorem

    +

    Rewriting the \( \delta \)-function

    -

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

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

    + +$$ + \delta(z-\frac{x_1+x_2+\dots+x_m}{m})=\frac{1}{2\pi}\int_{-\infty}^{\infty} + dq\exp{\left(iq(z-\frac{x_1+x_2+\dots+x_m}{m})\right)}, +$$ + +

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

    - -

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

    $$ - z=\frac{x_1+x_2+\dots+x_m}{m}, + \tilde{p}(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} + dq\exp{\left(iq(z-\mu)\right)}\left[\int_{-\infty}^{\infty} + dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m, +$$ + +

    with the integral over \( x \) resulting in

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

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

    @@ -333,7 +335,7 @@ $$

  • 40
  • 41
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs032.html b/doc/pub/week37/html/._week37-bs032.html index 54aaf07bc..7dd34d435 100644 --- a/doc/pub/week37/html/._week37-bs032.html +++ b/doc/pub/week37/html/._week37-bs032.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,22 +283,33 @@ MathJax.Hub.Config({

     

     

     

    -

    Finding the Limit

    +

    Identifying Terms

    -

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

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

    $$ - \tilde{p}(z)=\int dx_1p(x_1)\int dx_2p(x_2)\dots\int dx_mp(x_m) - \delta(z-\frac{x_1+x_2+\dots+x_m}{m}), + \int_{-\infty}^{\infty}dxp(x)e^{\left(iq(\mu-x)/m\right)}= + 1-\frac{q^2\sigma^2}{2m^2}+\dots, $$ -

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

    resulting in

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

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

    + +$$ + \tilde{p}(z)=\frac{1}{\sqrt{2\pi}(\sigma/\sqrt{m})} + \exp{\left(-\frac{(z-\mu)^2}{2(\sigma/\sqrt{m})^2}\right)}, +$$ + +

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

    @@ -333,7 +337,7 @@ product of individual \( p(x_i) \). The independence assumption is important in

  • 41
  • 42
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs033.html b/doc/pub/week37/html/._week37-bs033.html index 6e543cd17..f1e1ec47b 100644 --- a/doc/pub/week37/html/._week37-bs033.html +++ b/doc/pub/week37/html/._week37-bs033.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,32 +283,46 @@ MathJax.Hub.Config({

     

     

     

    -

    Rewriting the \( \delta \)-function

    +

    Wrapping it up

    -

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

    +

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

    + +

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

    $$ - \delta(z-\frac{x_1+x_2+\dots+x_m}{m})=\frac{1}{2\pi}\int_{-\infty}^{\infty} - dq\exp{\left(iq(z-\frac{x_1+x_2+\dots+x_m}{m})\right)}, + \sigma_m= +\frac{\sigma}{\sqrt{m}}. $$ -

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

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

    $$ - \tilde{p}(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} - dq\exp{\left(iq(z-\mu)\right)}\left[\int_{-\infty}^{\infty} - dxp(x)\exp{\left(iq(\mu-x)/m\right)}\right]^m, + \sigma_m\approx +\frac{\sigma}{\sqrt{m-1}}. $$ -

    with the integral over \( x \) resulting in

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

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

    +

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

    @@ -342,7 +349,7 @@ $$

  • 42
  • 43
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs034.html b/doc/pub/week37/html/._week37-bs034.html index ff7a5fe3f..4e93a3e15 100644 --- a/doc/pub/week37/html/._week37-bs034.html +++ b/doc/pub/week37/html/._week37-bs034.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,33 +283,23 @@ MathJax.Hub.Config({

     

     

     

    -

    Identifying Terms

    +

    Confidence Intervals

    -

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

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

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

    resulting in

    +

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

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

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

    -

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

    - -$$ - \tilde{p}(z)=\frac{1}{\sqrt{2\pi}(\sigma/\sqrt{m})} - \exp{\left(-\frac{(z-\mu)^2}{2(\sigma/\sqrt{m})^2}\right)}, -$$ - -

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

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

    @@ -344,7 +327,7 @@ and \( \mu \) is also the mean of the PDF \( p(x) \).

  • 43
  • 44
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs035.html b/doc/pub/week37/html/._week37-bs035.html index 2c3c7ace0..5a4d29bfb 100644 --- a/doc/pub/week37/html/._week37-bs035.html +++ b/doc/pub/week37/html/._week37-bs035.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,45 +283,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Wrapping it up

    +

    Standard Approach based on the Normal Distribution

    -

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

    - -

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

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

    $$ - \sigma_m= -\frac{\sigma}{\sqrt{m}}. +\left(\mu_{\beta}\pm \frac{z\sigma_{\beta}}{\sqrt{n}}\right), $$ -

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

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

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

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

    -

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

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

    + +

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

    @@ -356,7 +334,7 @@ finite \( m \), it is not always possible to find a closed form /analytic expres

  • 44
  • 45
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs036.html b/doc/pub/week37/html/._week37-bs036.html index 5bcea59eb..0905cbfcc 100644 --- a/doc/pub/week37/html/._week37-bs036.html +++ b/doc/pub/week37/html/._week37-bs036.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,23 +283,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Confidence Intervals

    +

    Resampling methods: Bootstrap background

    -

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

    - -

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

    - -

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

    - -

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

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

    @@ -334,7 +321,7 @@ construct a confidence interval for the estimates.

  • 45
  • 46
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs037.html b/doc/pub/week37/html/._week37-bs037.html index f7b4bbb81..8829ea157 100644 --- a/doc/pub/week37/html/._week37-bs037.html +++ b/doc/pub/week37/html/._week37-bs037.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,30 +283,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Standard Approach based on the Normal Distribution

    +

    Resampling methods: More Bootstrap background

    -

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

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

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

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

    - -

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

    - -

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

      +
    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. +
    3. Then using these numbers, we could compute a replica of \( \widehat{\beta} \) called \( \widehat{\beta}^* \).
    4. +
    +

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

    @@ -341,7 +326,7 @@ Bootstrap method, why it works and various theorems related to it.

  • 46
  • 47
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs038.html b/doc/pub/week37/html/._week37-bs038.html index db96c74d2..791e92139 100644 --- a/doc/pub/week37/html/._week37-bs038.html +++ b/doc/pub/week37/html/._week37-bs038.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,17 +283,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods: Bootstrap background

    +

    Resampling methods: Bootstrap approach

    -

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

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

    + +

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

    @@ -328,7 +323,7 @@ estimators.

  • 47
  • 48
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs039.html b/doc/pub/week37/html/._week37-bs039.html index f50f6d326..ac051d273 100644 --- a/doc/pub/week37/html/._week37-bs039.html +++ b/doc/pub/week37/html/._week37-bs039.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,22 +283,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods: More Bootstrap background

    +

    Resampling methods: Bootstrap steps

    + +

    The independent bootstrap works like this:

    -

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

      -
    1. Drawing lots of numbers from \( p(x) \), suppose we call one such set of numbers \( (X_1^*, X_2^*, \cdots, X_n^*) \).
    2. -
    3. Then using these numbers, we could compute a replica of \( \widehat{\beta} \) called \( \widehat{\beta}^* \).
    4. +
    5. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    6. +
    7. Define a vector \( \boldsymbol{x}^* \) containing the values which were drawn from \( \boldsymbol{x} \).
    8. +
    9. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\beta}^* \) by evaluating \( \widehat \beta \) under the observations \( \boldsymbol{x}^* \).
    10. +
    11. Repeat this process \( k \) times.
    -

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

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

    @@ -333,7 +329,7 @@ idea is to use the relative frequency of \( \widehat{\beta}^* \)

  • 48
  • 49
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs040.html b/doc/pub/week37/html/._week37-bs040.html index 45ca12c28..99939da47 100644 --- a/doc/pub/week37/html/._week37-bs040.html +++ b/doc/pub/week37/html/._week37-bs040.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,20 +283,71 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods: Bootstrap approach

    +

    Code example for the Bootstrap method

    -

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

    The following code starts with a Gaussian distribution with mean value +\( \mu =100 \) and variance \( \sigma=15 \). We use this to generate the data +used in the bootstrap analysis. The bootstrap analysis returns a data +set after a given number of bootstrap operations (as many as we have +data points). This data set consists of estimated mean values for each +bootstrap operation. The histogram generated by the bootstrap method +shows that the distribution for these mean values is also a Gaussian, +centered around the mean value \( \mu=100 \) but with standard deviation +\( \sigma/\sqrt{n} \), where \( n \) is the number of bootstrap samples (in +this case the same as the number of original data points). The value +of the standard deviation is what we expect from the central limit +theorem.

    -

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

    + + +
    +
    +
    +
    +
    +
    import numpy as np
    +from time import time
    +from scipy.stats import norm
    +import matplotlib.pyplot as plt
    +
    +# Returns mean of bootstrap samples 
    +# Bootstrap algorithm
    +def bootstrap(data, datapoints):
    +    t = np.zeros(datapoints)
    +    n = len(data)
    +    # non-parametric bootstrap         
    +    for i in range(datapoints):
    +        t[i] = np.mean(data[np.random.randint(0,n,n)])
    +    # analysis    
    +    print("Bootstrap Statistics :")
    +    print("original           bias      std. error")
    +    print("%8g %8g %14g %15g" % (np.mean(data), np.std(data),np.mean(t),np.std(t)))
    +    return t
    +
    +# We set the mean value to 100 and the standard deviation to 15
    +mu, sigma = 100, 15
    +datapoints = 10000
    +# We generate random numbers according to the normal distribution
    +x = mu + sigma*np.random.randn(datapoints)
    +# bootstrap returns the data sample                                    
    +t = bootstrap(x, datapoints)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

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

    @@ -330,7 +374,7 @@ result in some asymptotic sense? The answer is yes.

  • 49
  • 50
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs041.html b/doc/pub/week37/html/._week37-bs041.html index e645b7948..4424b0e30 100644 --- a/doc/pub/week37/html/._week37-bs041.html +++ b/doc/pub/week37/html/._week37-bs041.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,26 +283,38 @@ MathJax.Hub.Config({

     

     

     

    -

    Resampling methods: Bootstrap steps

    +

    Plotting the Histogram

    -

    The independent bootstrap works like this:

    + +
    +
    +
    +
    +
    +
    # the histogram of the bootstrapped data (normalized data if density = True)
    +n, binsboot, patches = plt.hist(t, 50, density=True, facecolor='red', alpha=0.75)
    +# add a 'best fit' line  
    +y = norm.pdf(binsboot, np.mean(t), np.std(t))
    +lt = plt.plot(binsboot, y, 'b', linewidth=1)
    +plt.xlabel('x')
    +plt.ylabel('Probability')
    +plt.grid(True)
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -
      -
    1. Draw with replacement \( n \) numbers for the observed variables \( \boldsymbol{x} = (x_1,x_2,\cdots,x_n) \).
    2. -
    3. Define a vector \( \boldsymbol{x}^* \) containing the values which were drawn from \( \boldsymbol{x} \).
    4. -
    5. Using the vector \( \boldsymbol{x}^* \) compute \( \widehat{\beta}^* \) by evaluating \( \widehat \beta \) under the observations \( \boldsymbol{x}^* \).
    6. -
    7. Repeat this process \( k \) times.
    8. -
    -

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

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

  • 50
  • 51
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs042.html b/doc/pub/week37/html/._week37-bs042.html index 441da945a..2f52f314c 100644 --- a/doc/pub/week37/html/._week37-bs042.html +++ b/doc/pub/week37/html/._week37-bs042.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,71 +283,64 @@ MathJax.Hub.Config({

     

     

     

    -

    Code example for the Bootstrap method

    +

    The bias-variance tradeoff

    -

    The following code starts with a Gaussian distribution with mean value -\( \mu =100 \) and variance \( \sigma=15 \). We use this to generate the data -used in the bootstrap analysis. The bootstrap analysis returns a data -set after a given number of bootstrap operations (as many as we have -data points). This data set consists of estimated mean values for each -bootstrap operation. The histogram generated by the bootstrap method -shows that the distribution for these mean values is also a Gaussian, -centered around the mean value \( \mu=100 \) but with standard deviation -\( \sigma/\sqrt{n} \), where \( n \) is the number of bootstrap samples (in -this case the same as the number of original data points). The value -of the standard deviation is what we expect from the central limit -theorem. +

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

    +

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

    - -
    -
    -
    -
    -
    -
    import numpy as np
    -from time import time
    -from scipy.stats import norm
    -import matplotlib.pyplot as plt
    +$$
    +\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon}
    +$$
     
    -# Returns mean of bootstrap samples 
    -# Bootstrap algorithm
    -def bootstrap(data, datapoints):
    -    t = np.zeros(datapoints)
    -    n = len(data)
    -    # non-parametric bootstrap         
    -    for i in range(datapoints):
    -        t[i] = np.mean(data[np.random.randint(0,n,n)])
    -    # analysis    
    -    print("Bootstrap Statistics :")
    -    print("original           bias      std. error")
    -    print("%8g %8g %14g %15g" % (np.mean(data), np.std(data),np.mean(t),np.std(t)))
    -    return t
    +

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

    -# We set the mean value to 100 and the standard deviation to 15 -mu, sigma = 100, 15 -datapoints = 10000 -# We generate random numbers according to the normal distribution -x = mu + sigma*np.random.randn(datapoints) -# bootstrap returns the data sample -t = bootstrap(x, datapoints) -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

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

    -

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

    +

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

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

    We can rewrite this as

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

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

    + +

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

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

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

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

    which, using the abovementioned expectation values can be rewritten as

    +$$ +\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{y}-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\boldsymbol{\tilde{y}}\right]+\sigma^2, +$$ + +

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

    @@ -381,7 +367,7 @@ t = bootstrap(x, datapoints)

  • 51
  • 52
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs043.html b/doc/pub/week37/html/._week37-bs043.html index a2bd52fc6..0417ce3df 100644 --- a/doc/pub/week37/html/._week37-bs043.html +++ b/doc/pub/week37/html/._week37-bs043.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,38 +283,13 @@ MathJax.Hub.Config({

     

     

     

    -

    Plotting the Histogram

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

    A way to Read the Bias-Variance Tradeoff

    +

    +
    +

    +
    +

    @@ -347,8 +315,6 @@ plt.show()

  • 51
  • 52
  • 53
  • -
  • ...
  • -
  • 55
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs044.html b/doc/pub/week37/html/._week37-bs044.html index d67bf9529..49d6712e7 100644 --- a/doc/pub/week37/html/._week37-bs044.html +++ b/doc/pub/week37/html/._week37-bs044.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,64 +283,83 @@ MathJax.Hub.Config({

     

     

     

    -

    The bias-variance tradeoff

    +

    Example code for Bias-Variance tradeoff

    -

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

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

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

    +np.random.seed(2018) -$$ -\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon} -$$ +n = 500 +n_boostraps = 100 +degree = 18 # A quite high value, just to show. +noise = 0.1 -

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

    +# Make data set. +x = np.linspace(-1, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) + np.random.normal(0, 0.1, x.shape) -

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

    +# Hold out some test data that is never used in training. +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) -

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

    -$$ -C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]. -$$ +# Combine x transformation and model into one operation. +# Not neccesary, but convenient. +model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) -

    We can rewrite this as

    -$$ -\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2. -$$ +# The following (m x n_bootstraps) matrix holds the column vectors y_pred +# for each bootstrap iteration. +y_pred = np.empty((y_test.shape[0], n_boostraps)) +for i in range(n_boostraps): + x_, y_ = resample(x_train, y_train) -

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

    + # Evaluate the new model on the same test data each time. + y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() -

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

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

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

    -$$ -\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{f}+\boldsymbol{\epsilon}-\boldsymbol{\tilde{y}}+\mathbb{E}\left[\boldsymbol{\tilde{y}}\right]-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right], -$$ +plt.plot(x[::5, :], y[::5, :], label='f(x)') +plt.scatter(x_test, y_test, label='Data points') +plt.scatter(x_test, np.mean(y_pred, axis=1), label='Pred') +plt.legend() +plt.show() +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    which, using the abovementioned expectation values can be rewritten as

    -$$ -\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\mathbb{E}\left[(\boldsymbol{y}-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\boldsymbol{\tilde{y}}\right]+\sigma^2, -$$ - -

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

    @@ -372,9 +384,6 @@ $$

  • 51
  • 52
  • 53
  • -
  • 54
  • -
  • ...
  • -
  • 55
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs045.html b/doc/pub/week37/html/._week37-bs045.html index 71a6a564c..f67ed982c 100644 --- a/doc/pub/week37/html/._week37-bs045.html +++ b/doc/pub/week37/html/._week37-bs045.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,13 +283,75 @@ MathJax.Hub.Config({

     

     

     

    -

    A way to Read the Bias-Variance Tradeoff

    +

    Understanding what happens

    + + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.linear_model import LinearRegression, Ridge, Lasso
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.model_selection import train_test_split
    +from sklearn.pipeline import make_pipeline
    +from sklearn.utils import resample
    +
    +np.random.seed(2018)
    +
    +n = 40
    +n_boostraps = 100
    +maxdegree = 14
    +
    +
    +# Make data set.
    +x = np.linspace(-3, 3, n).reshape(-1, 1)
    +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    +error = np.zeros(maxdegree)
    +bias = np.zeros(maxdegree)
    +variance = np.zeros(maxdegree)
    +polydegree = np.zeros(maxdegree)
    +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
    +
    +for degree in range(maxdegree):
    +    model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
    +    y_pred = np.empty((y_test.shape[0], n_boostraps))
    +    for i in range(n_boostraps):
    +        x_, y_ = resample(x_train, y_train)
    +        y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel()
    +
    +    polydegree[degree] = degree
    +    error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
    +    bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
    +    variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
    +    print('Polynomial degree:', degree)
    +    print('Error:', error[degree])
    +    print('Bias^2:', bias[degree])
    +    print('Var:', variance[degree])
    +    print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
    +
    +plt.plot(polydegree, error, label='Error')
    +plt.plot(polydegree, bias, label='bias')
    +plt.plot(polydegree, variance, label='Variance')
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    -
    -

    -
    -

    @@ -320,8 +375,6 @@ MathJax.Hub.Config({

  • 51
  • 52
  • 53
  • -
  • 54
  • -
  • 55
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs046.html b/doc/pub/week37/html/._week37-bs046.html index 6204b1a48..bf4f7de79 100644 --- a/doc/pub/week37/html/._week37-bs046.html +++ b/doc/pub/week37/html/._week37-bs046.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -289,84 +282,39 @@ MathJax.Hub.Config({

     

     

     

    - -

    Example code for Bias-Variance tradeoff

    + +

    Summing up

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

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

    -np.random.seed(2018) +

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

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

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

    +

    You may also find this recent article of interest.

    @@ -389,8 +337,6 @@ plt.show()

  • 51
  • 52
  • 53
  • -
  • 54
  • -
  • 55
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs047.html b/doc/pub/week37/html/._week37-bs047.html index 719c50e34..4f56d3f72 100644 --- a/doc/pub/week37/html/._week37-bs047.html +++ b/doc/pub/week37/html/._week37-bs047.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,7 +283,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Understanding what happens

    +

    Another Example from Scikit-Learn's Repository

    @@ -298,51 +291,76 @@ MathJax.Hub.Config({
    -
    import matplotlib.pyplot as plt
    +  
    """
    +============================
    +Underfitting vs. Overfitting
    +============================
    +
    +This example demonstrates the problems of underfitting and overfitting and
    +how we can use linear regression with polynomial features to approximate
    +nonlinear functions. The plot shows the function that we want to approximate,
    +which is a part of the cosine function. In addition, the samples from the
    +real function and the approximations of different models are displayed. The
    +models have polynomial features of different degrees. We can see that a
    +linear function (polynomial with degree 1) is not sufficient to fit the
    +training samples. This is called **underfitting**. A polynomial of degree 4
    +approximates the true function almost perfectly. However, for higher degrees
    +the model will **overfit** the training data, i.e. it learns the noise of the
    +training data.
    +We evaluate quantitatively **overfitting** / **underfitting** by using
    +cross-validation. We calculate the mean squared error (MSE) on the validation
    +set, the higher, the less likely the model generalizes correctly from the
    +training data.
    +"""
    +
    +print(__doc__)
    +
     import numpy as np
    -from sklearn.linear_model import LinearRegression, Ridge, Lasso
    +import matplotlib.pyplot as plt
    +from sklearn.pipeline import Pipeline
     from sklearn.preprocessing import PolynomialFeatures
    -from sklearn.model_selection import train_test_split
    -from sklearn.pipeline import make_pipeline
    -from sklearn.utils import resample
    -
    -np.random.seed(2018)
    -
    -n = 40
    -n_boostraps = 100
    -maxdegree = 14
    +from sklearn.linear_model import LinearRegression
    +from sklearn.model_selection import cross_val_score
     
     
    -# Make data set.
    -x = np.linspace(-3, 3, n).reshape(-1, 1)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    -error = np.zeros(maxdegree)
    -bias = np.zeros(maxdegree)
    -variance = np.zeros(maxdegree)
    -polydegree = np.zeros(maxdegree)
    -x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
    +def true_fun(X):
    +    return np.cos(1.5 * np.pi * X)
     
    -for degree in range(maxdegree):
    -    model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
    -    y_pred = np.empty((y_test.shape[0], n_boostraps))
    -    for i in range(n_boostraps):
    -        x_, y_ = resample(x_train, y_train)
    -        y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel()
    +np.random.seed(0)
     
    -    polydegree[degree] = degree
    -    error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
    -    bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
    -    variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
    -    print('Polynomial degree:', degree)
    -    print('Error:', error[degree])
    -    print('Bias^2:', bias[degree])
    -    print('Var:', variance[degree])
    -    print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
    +n_samples = 30
    +degrees = [1, 4, 15]
     
    -plt.plot(polydegree, error, label='Error')
    -plt.plot(polydegree, bias, label='bias')
    -plt.plot(polydegree, variance, label='Variance')
    -plt.legend()
    +X = np.sort(np.random.rand(n_samples))
    +y = true_fun(X) + np.random.randn(n_samples) * 0.1
    +
    +plt.figure(figsize=(14, 5))
    +for i in range(len(degrees)):
    +    ax = plt.subplot(1, len(degrees), i + 1)
    +    plt.setp(ax, xticks=(), yticks=())
    +
    +    polynomial_features = PolynomialFeatures(degree=degrees[i],
    +                                             include_bias=False)
    +    linear_regression = LinearRegression()
    +    pipeline = Pipeline([("polynomial_features", polynomial_features),
    +                         ("linear_regression", linear_regression)])
    +    pipeline.fit(X[:, np.newaxis], y)
    +
    +    # Evaluate the models using crossvalidation
    +    scores = cross_val_score(pipeline, X[:, np.newaxis], y,
    +                             scoring="neg_mean_squared_error", cv=10)
    +
    +    X_test = np.linspace(0, 1, 100)
    +    plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label="Model")
    +    plt.plot(X_test, true_fun(X_test), label="True function")
    +    plt.scatter(X, y, edgecolor='b', s=20, label="Samples")
    +    plt.xlabel("x")
    +    plt.ylabel("y")
    +    plt.xlim((0, 1))
    +    plt.ylim((-2, 2))
    +    plt.legend(loc="best")
    +    plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
    +        degrees[i], -scores.mean(), scores.std()))
     plt.show()
     
    @@ -380,8 +398,6 @@ plt.show()
  • 51
  • 52
  • 53
  • -
  • 54
  • -
  • 55
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs048.html b/doc/pub/week37/html/._week37-bs048.html index ab14bd60b..a3e322167 100644 --- a/doc/pub/week37/html/._week37-bs048.html +++ b/doc/pub/week37/html/._week37-bs048.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,39 +283,24 @@ MathJax.Hub.Config({

     

     

     

    -

    Summing up

    +

    Various steps in cross-validation

    -

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

    When the repetitive splitting of the data set is done randomly, +samples may accidently end up in a fast majority of the splits in +either training or test set. Such samples may have an unbalanced +influence on either model building or prediction evaluation. To avoid +this \( k \)-fold cross-validation structures the data splitting. The +samples are divided into \( k \) more or less equally sized exhaustive and +mutually exclusive subsets. In turn (at each split) one of these +subsets plays the role of the test set while the union of the +remaining subsets constitutes the training set. Such a splitting +warrants a balanced representation of each sample in both training and +test set over the splits. Still the division into the \( k \) subsets +involves a degree of randomness. This may be fully excluded when +choosing \( k=n \). This particular case is referred to as leave-one-out +cross-validation (LOOCV).

    -

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

    - -

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

    - -

    You may also find this recent article of interest.

    -

      @@ -342,8 +320,6 @@ flexible statistical methods have higher variance.
    • 51
    • 52
    • 53
    • -
    • 54
    • -
    • 55
    • »
    diff --git a/doc/pub/week37/html/._week37-bs049.html b/doc/pub/week37/html/._week37-bs049.html index de5e548cb..beebc529a 100644 --- a/doc/pub/week37/html/._week37-bs049.html +++ b/doc/pub/week37/html/._week37-bs049.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -290,101 +283,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Another Example from Scikit-Learn's Repository

    - - -
    -
    -
    -
    -
    -
    """
    -============================
    -Underfitting vs. Overfitting
    -============================
    -
    -This example demonstrates the problems of underfitting and overfitting and
    -how we can use linear regression with polynomial features to approximate
    -nonlinear functions. The plot shows the function that we want to approximate,
    -which is a part of the cosine function. In addition, the samples from the
    -real function and the approximations of different models are displayed. The
    -models have polynomial features of different degrees. We can see that a
    -linear function (polynomial with degree 1) is not sufficient to fit the
    -training samples. This is called **underfitting**. A polynomial of degree 4
    -approximates the true function almost perfectly. However, for higher degrees
    -the model will **overfit** the training data, i.e. it learns the noise of the
    -training data.
    -We evaluate quantitatively **overfitting** / **underfitting** by using
    -cross-validation. We calculate the mean squared error (MSE) on the validation
    -set, the higher, the less likely the model generalizes correctly from the
    -training data.
    -"""
    -
    -print(__doc__)
    -
    -import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn.pipeline import Pipeline
    -from sklearn.preprocessing import PolynomialFeatures
    -from sklearn.linear_model import LinearRegression
    -from sklearn.model_selection import cross_val_score
    -
    -
    -def true_fun(X):
    -    return np.cos(1.5 * np.pi * X)
    -
    -np.random.seed(0)
    -
    -n_samples = 30
    -degrees = [1, 4, 15]
    -
    -X = np.sort(np.random.rand(n_samples))
    -y = true_fun(X) + np.random.randn(n_samples) * 0.1
    -
    -plt.figure(figsize=(14, 5))
    -for i in range(len(degrees)):
    -    ax = plt.subplot(1, len(degrees), i + 1)
    -    plt.setp(ax, xticks=(), yticks=())
    -
    -    polynomial_features = PolynomialFeatures(degree=degrees[i],
    -                                             include_bias=False)
    -    linear_regression = LinearRegression()
    -    pipeline = Pipeline([("polynomial_features", polynomial_features),
    -                         ("linear_regression", linear_regression)])
    -    pipeline.fit(X[:, np.newaxis], y)
    -
    -    # Evaluate the models using crossvalidation
    -    scores = cross_val_score(pipeline, X[:, np.newaxis], y,
    -                             scoring="neg_mean_squared_error", cv=10)
    -
    -    X_test = np.linspace(0, 1, 100)
    -    plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label="Model")
    -    plt.plot(X_test, true_fun(X_test), label="True function")
    -    plt.scatter(X, y, edgecolor='b', s=20, label="Samples")
    -    plt.xlabel("x")
    -    plt.ylabel("y")
    -    plt.xlim((0, 1))
    -    plt.ylim((-2, 2))
    -    plt.legend(loc="best")
    -    plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
    -        degrees[i], -scores.mean(), scores.std()))
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    Cross-validation in brief

    +

    For the various values of \( k \)

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

    diff --git a/doc/pub/week37/html/week37-bs.html b/doc/pub/week37/html/week37-bs.html index d3cd07a53..e3771e97a 100644 --- a/doc/pub/week37/html/week37-bs.html +++ b/doc/pub/week37/html/week37-bs.html @@ -94,11 +94,6 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -246,39 +241,37 @@ MathJax.Hub.Config({
  • Bayes' Theorem and Ridge and Lasso Regression
  • Ridge and Bayes
  • Lasso and Bayes
  • -
  • Test Function for what happens with OLS, Ridge and Lasso
  • -
  • Rerunning the above code
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Bootstrap
  • -
  • The Central Limit Theorem
  • -
  • Finding the Limit
  • -
  • Rewriting the \( \delta \)-function
  • -
  • Identifying Terms
  • -
  • Wrapping it up
  • -
  • Confidence Intervals
  • -
  • Standard Approach based on the Normal Distribution
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Plotting the Histogram
  • -
  • The bias-variance tradeoff
  • -
  • A way to Read the Bias-Variance Tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • Various steps in cross-validation
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Bootstrap
  • +
  • The Central Limit Theorem
  • +
  • Finding the Limit
  • +
  • Rewriting the \( \delta \)-function
  • +
  • Identifying Terms
  • +
  • Wrapping it up
  • +
  • Confidence Intervals
  • +
  • Standard Approach based on the Normal Distribution
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Plotting the Histogram
  • +
  • The bias-variance tradeoff
  • +
  • A way to Read the Bias-Variance Tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • Various steps in cross-validation
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • @@ -335,7 +328,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 55
  • +
  • 53
  • »
  • diff --git a/doc/pub/week37/html/week37-reveal.html b/doc/pub/week37/html/week37-reveal.html index 702dc9460..2577ae9be 100644 --- a/doc/pub/week37/html/week37-reveal.html +++ b/doc/pub/week37/html/week37-reveal.html @@ -865,192 +865,6 @@ $$

    which is our Lasso cost function!

    -
    -

    Test Function for what happens with OLS, Ridge and Lasso

    - -

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

    - -

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

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

    How can we understand this?

    -
    - -
    -

    Rerunning the above code

    - -

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

    - -

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

    - -

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

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -from IPython.display import display
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    -
    -# Make data set.
    -n = 1000
    -x = np.random.rand(n)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    -
    -Maxpolydegree = 5
    -X = np.zeros((len(x),Maxpolydegree))
    -X[:,0] = 1.0
    -
    -for polydegree in range(1, Maxpolydegree+1):
    -    for degree in range(polydegree):
    -        X[:,degree] = x**(degree)
    -
    -
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# Decide which values of lambda to use
    -nlambdas = 5
    -lambdas = np.logspace(-3, 2, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    # Make the fit using Ridge only
    -    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    -    RegRidge.fit(X_train,y_train)
    -    # and then make the prediction
    -    ypredictRidge = RegRidge.predict(X_test)
    -    Coeffs = np.array(RegRidge.coef_)
    -    BetaValues = pd.DataFrame(Coeffs)
    -    BetaValues.columns = ['beta']
    -    display(BetaValues)    
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    Why resampling methods

    diff --git a/doc/pub/week37/html/week37-solarized.html b/doc/pub/week37/html/week37-solarized.html index 8cef67364..a51f2bc15 100644 --- a/doc/pub/week37/html/week37-solarized.html +++ b/doc/pub/week37/html/week37-solarized.html @@ -121,11 +121,6 @@ div.toc p,a { 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -821,191 +816,6 @@ $$

    which is our Lasso cost function!

    -









    -

    Test Function for what happens with OLS, Ridge and Lasso

    - -

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

    - -

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

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

    How can we understand this?

    - -









    -

    Rerunning the above code

    - -

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

    - -

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

    - -

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

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -from IPython.display import display
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    -
    -# Make data set.
    -n = 1000
    -x = np.random.rand(n)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    -
    -Maxpolydegree = 5
    -X = np.zeros((len(x),Maxpolydegree))
    -X[:,0] = 1.0
    -
    -for polydegree in range(1, Maxpolydegree+1):
    -    for degree in range(polydegree):
    -        X[:,degree] = x**(degree)
    -
    -
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# Decide which values of lambda to use
    -nlambdas = 5
    -lambdas = np.logspace(-3, 2, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    # Make the fit using Ridge only
    -    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    -    RegRidge.fit(X_train,y_train)
    -    # and then make the prediction
    -    ypredictRidge = RegRidge.predict(X_test)
    -    Coeffs = np.array(RegRidge.coef_)
    -    BetaValues = pd.DataFrame(Coeffs)
    -    BetaValues.columns = ['beta']
    -    display(BetaValues)    
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -









    Why resampling methods

    diff --git a/doc/pub/week37/html/week37.html b/doc/pub/week37/html/week37.html index 6833d1fed..36b9a8c22 100644 --- a/doc/pub/week37/html/week37.html +++ b/doc/pub/week37/html/week37.html @@ -198,11 +198,6 @@ div.toc p,a { 'bayes-theorem-and-ridge-and-lasso-regression'), ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Test Function for what happens with OLS, Ridge and Lasso', - 2, - None, - 'test-function-for-what-happens-with-ols-ridge-and-lasso'), - ('Rerunning the above code', 2, None, 'rerunning-the-above-code'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -898,191 +893,6 @@ $$

    which is our Lasso cost function!

    -









    -

    Test Function for what happens with OLS, Ridge and Lasso

    - -

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

    - -

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

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

    How can we understand this?

    - -









    -

    Rerunning the above code

    - -

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

    - -

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

    - -

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

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import pandas as pd
    -from IPython.display import display
    -import matplotlib.pyplot as plt
    -from sklearn.model_selection import train_test_split
    -from sklearn import linear_model
    -
    -# Make data set.
    -n = 1000
    -x = np.random.rand(n)
    -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)
    -
    -Maxpolydegree = 5
    -X = np.zeros((len(x),Maxpolydegree))
    -X[:,0] = 1.0
    -
    -for polydegree in range(1, Maxpolydegree+1):
    -    for degree in range(polydegree):
    -        X[:,degree] = x**(degree)
    -
    -
    -# We split the data in test and training data
    -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    -
    -# Decide which values of lambda to use
    -nlambdas = 5
    -lambdas = np.logspace(-3, 2, nlambdas)
    -for i in range(nlambdas):
    -    lmb = lambdas[i]
    -    # Make the fit using Ridge only
    -    RegRidge = linear_model.Ridge(lmb,fit_intercept=False)
    -    RegRidge.fit(X_train,y_train)
    -    # and then make the prediction
    -    ypredictRidge = RegRidge.predict(X_test)
    -    Coeffs = np.array(RegRidge.coef_)
    -    BetaValues = pd.DataFrame(Coeffs)
    -    BetaValues.columns = ['beta']
    -    display(BetaValues)    
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -









    Why resampling methods

    diff --git a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz index 1499c5c00..50a1670e2 100644 Binary files a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz and b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz differ diff --git a/doc/pub/week37/ipynb/week37.ipynb b/doc/pub/week37/ipynb/week37.ipynb index 181bc4287..9ad8b75e2 100644 --- a/doc/pub/week37/ipynb/week37.ipynb +++ b/doc/pub/week37/ipynb/week37.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "037efae8", + "id": "6e75c2b2", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "8c279dac", + "id": "223c3ed9", "metadata": { "editable": true }, @@ -31,7 +31,7 @@ }, { "cell_type": "markdown", - "id": "f01225b0", + "id": "324d3c32", "metadata": { "editable": true }, @@ -68,7 +68,7 @@ }, { "cell_type": "markdown", - "id": "dcaacb29", + "id": "d663b9d2", "metadata": { "editable": true }, @@ -78,7 +78,7 @@ }, { "cell_type": "markdown", - "id": "7cd762c8", + "id": "f311473b", "metadata": { "editable": true }, @@ -107,7 +107,7 @@ }, { "cell_type": "markdown", - "id": "2f2a8b31", + "id": "7c03ce11", "metadata": { "editable": true }, @@ -123,7 +123,7 @@ }, { "cell_type": "markdown", - "id": "cd382b8e", + "id": "6e2c762f", "metadata": { "editable": true }, @@ -142,7 +142,7 @@ }, { "cell_type": "markdown", - "id": "84b4b211", + "id": "4627685b", "metadata": { "editable": true }, @@ -156,7 +156,7 @@ }, { "cell_type": "markdown", - "id": "78a892f4", + "id": "6e7897ae", "metadata": { "editable": true }, @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "e56477ef", + "id": "b3ae81a0", "metadata": { "editable": true }, @@ -179,7 +179,7 @@ }, { "cell_type": "markdown", - "id": "99efd6e4", + "id": "624e3a17", "metadata": { "editable": true }, @@ -191,7 +191,7 @@ }, { "cell_type": "markdown", - "id": "e176bd50", + "id": "05fea861", "metadata": { "editable": true }, @@ -203,7 +203,7 @@ }, { "cell_type": "markdown", - "id": "e539a799", + "id": "58f9c428", "metadata": { "editable": true }, @@ -219,7 +219,7 @@ }, { "cell_type": "markdown", - "id": "ca7f347e", + "id": "0e188a35", "metadata": { "editable": true }, @@ -230,7 +230,7 @@ }, { "cell_type": "markdown", - "id": "6eeeb9cd", + "id": "f94f15b1", "metadata": { "editable": true }, @@ -253,7 +253,7 @@ }, { "cell_type": "markdown", - "id": "e03edff3", + "id": "16cd0fdc", "metadata": { "editable": true }, @@ -264,7 +264,7 @@ }, { "cell_type": "markdown", - "id": "eee642cd", + "id": "f7c4a9f9", "metadata": { "editable": true }, @@ -276,7 +276,7 @@ }, { "cell_type": "markdown", - "id": "bba0ff50", + "id": "53797dc4", "metadata": { "editable": true }, @@ -288,7 +288,7 @@ }, { "cell_type": "markdown", - "id": "7768c4c2", + "id": "a6d40f0b", "metadata": { "editable": true }, @@ -302,7 +302,7 @@ }, { "cell_type": "markdown", - "id": "1c384544", + "id": "8fb332ff", "metadata": { "editable": true }, @@ -333,7 +333,7 @@ }, { "cell_type": "markdown", - "id": "88bed314", + "id": "ca39cad2", "metadata": { "editable": true }, @@ -355,7 +355,7 @@ }, { "cell_type": "markdown", - "id": "d2686e16", + "id": "dba4b075", "metadata": { "editable": true }, @@ -367,7 +367,7 @@ }, { "cell_type": "markdown", - "id": "b2d862c3", + "id": "4c25cc4c", "metadata": { "editable": true }, @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "eb0e4d3a", + "id": "18952136", "metadata": { "editable": true }, @@ -392,7 +392,7 @@ }, { "cell_type": "markdown", - "id": "0a8b638b", + "id": "dfc4fe1f", "metadata": { "editable": true }, @@ -404,7 +404,7 @@ }, { "cell_type": "markdown", - "id": "9f9038fa", + "id": "a3c3da30", "metadata": { "editable": true }, @@ -416,7 +416,7 @@ }, { "cell_type": "markdown", - "id": "d3fd4d21", + "id": "5de3ef86", "metadata": { "editable": true }, @@ -430,7 +430,7 @@ }, { "cell_type": "markdown", - "id": "def394d7", + "id": "08df32bd", "metadata": { "editable": true }, @@ -440,7 +440,7 @@ }, { "cell_type": "markdown", - "id": "3d3270fa", + "id": "53271655", "metadata": { "editable": true }, @@ -463,7 +463,7 @@ }, { "cell_type": "markdown", - "id": "77d23eb7", + "id": "a4701fc6", "metadata": { "editable": true }, @@ -475,7 +475,7 @@ }, { "cell_type": "markdown", - "id": "b912a79c", + "id": "6da5e98b", "metadata": { "editable": true }, @@ -488,7 +488,7 @@ }, { "cell_type": "markdown", - "id": "ca2efc0c", + "id": "41ab5ec4", "metadata": { "editable": true }, @@ -500,7 +500,7 @@ }, { "cell_type": "markdown", - "id": "d0cadf0e", + "id": "876a837d", "metadata": { "editable": true }, @@ -512,7 +512,7 @@ }, { "cell_type": "markdown", - "id": "90e625bf", + "id": "8bee0ca5", "metadata": { "editable": true }, @@ -524,7 +524,7 @@ }, { "cell_type": "markdown", - "id": "ae8c7645", + "id": "a86dbb29", "metadata": { "editable": true }, @@ -535,7 +535,7 @@ }, { "cell_type": "markdown", - "id": "837aeb70", + "id": "17a9df19", "metadata": { "editable": true }, @@ -547,7 +547,7 @@ }, { "cell_type": "markdown", - "id": "c59eff2a", + "id": "96399230", "metadata": { "editable": true }, @@ -558,7 +558,7 @@ }, { "cell_type": "markdown", - "id": "689d52c6", + "id": "eee8bab8", "metadata": { "editable": true }, @@ -570,7 +570,7 @@ }, { "cell_type": "markdown", - "id": "72998727", + "id": "74e4661f", "metadata": { "editable": true }, @@ -580,7 +580,7 @@ }, { "cell_type": "markdown", - "id": "fe395e09", + "id": "0ae8e89b", "metadata": { "editable": true }, @@ -611,7 +611,7 @@ }, { "cell_type": "markdown", - "id": "662b9c02", + "id": "ff614284", "metadata": { "editable": true }, @@ -623,7 +623,7 @@ }, { "cell_type": "markdown", - "id": "fc1fbbf6", + "id": "993ed1ad", "metadata": { "editable": true }, @@ -635,7 +635,7 @@ }, { "cell_type": "markdown", - "id": "ee40eafe", + "id": "e652574c", "metadata": { "editable": true }, @@ -645,7 +645,7 @@ }, { "cell_type": "markdown", - "id": "b97af598", + "id": "211d02e7", "metadata": { "editable": true }, @@ -657,7 +657,7 @@ }, { "cell_type": "markdown", - "id": "4120da4c", + "id": "ba4baa60", "metadata": { "editable": true }, @@ -667,7 +667,7 @@ }, { "cell_type": "markdown", - "id": "12899a67", + "id": "d60b0f63", "metadata": { "editable": true }, @@ -679,7 +679,7 @@ }, { "cell_type": "markdown", - "id": "e70b0a39", + "id": "a757c673", "metadata": { "editable": true }, @@ -689,7 +689,7 @@ }, { "cell_type": "markdown", - "id": "a89268a5", + "id": "7252faf6", "metadata": { "editable": true }, @@ -701,7 +701,7 @@ }, { "cell_type": "markdown", - "id": "9aa568cb", + "id": "6c2d62b5", "metadata": { "editable": true }, @@ -711,7 +711,7 @@ }, { "cell_type": "markdown", - "id": "fc097127", + "id": "e4c88c81", "metadata": { "editable": true }, @@ -731,7 +731,7 @@ }, { "cell_type": "markdown", - "id": "b7812b8c", + "id": "dd281e40", "metadata": { "editable": true }, @@ -743,7 +743,7 @@ }, { "cell_type": "markdown", - "id": "db0a2e1e", + "id": "7b2b8183", "metadata": { "editable": true }, @@ -753,7 +753,7 @@ }, { "cell_type": "markdown", - "id": "7f6d4906", + "id": "827eb828", "metadata": { "editable": true }, @@ -765,7 +765,7 @@ }, { "cell_type": "markdown", - "id": "34871a32", + "id": "d0345913", "metadata": { "editable": true }, @@ -777,7 +777,7 @@ }, { "cell_type": "markdown", - "id": "663a4d91", + "id": "677a851e", "metadata": { "editable": true }, @@ -789,7 +789,7 @@ }, { "cell_type": "markdown", - "id": "96f3a971", + "id": "99ebc0ee", "metadata": { "editable": true }, @@ -801,7 +801,7 @@ }, { "cell_type": "markdown", - "id": "02389a2b", + "id": "2f59e610", "metadata": { "editable": true }, @@ -813,7 +813,7 @@ }, { "cell_type": "markdown", - "id": "7f51d96f", + "id": "01fa86b5", "metadata": { "editable": true }, @@ -825,7 +825,7 @@ }, { "cell_type": "markdown", - "id": "70efa478", + "id": "74e827ef", "metadata": { "editable": true }, @@ -837,7 +837,7 @@ }, { "cell_type": "markdown", - "id": "d92b2f69", + "id": "087fdd2d", "metadata": { "editable": true }, @@ -849,7 +849,7 @@ }, { "cell_type": "markdown", - "id": "46fb446d", + "id": "f7a72d7f", "metadata": { "editable": true }, @@ -859,7 +859,7 @@ }, { "cell_type": "markdown", - "id": "0e4918f8", + "id": "b27f248b", "metadata": { "editable": true }, @@ -871,7 +871,7 @@ }, { "cell_type": "markdown", - "id": "026ec51a", + "id": "81ea750a", "metadata": { "editable": true }, @@ -881,7 +881,7 @@ }, { "cell_type": "markdown", - "id": "dfa6326e", + "id": "95ea7b54", "metadata": { "editable": true }, @@ -900,7 +900,7 @@ }, { "cell_type": "markdown", - "id": "1f24de0c", + "id": "e5dacbf5", "metadata": { "editable": true }, @@ -921,7 +921,7 @@ }, { "cell_type": "markdown", - "id": "fce57274", + "id": "859ef9cf", "metadata": { "editable": true }, @@ -933,7 +933,7 @@ }, { "cell_type": "markdown", - "id": "4e67d0ad", + "id": "6216acec", "metadata": { "editable": true }, @@ -944,7 +944,7 @@ }, { "cell_type": "markdown", - "id": "891e5096", + "id": "7adb6a4b", "metadata": { "editable": true }, @@ -957,7 +957,7 @@ }, { "cell_type": "markdown", - "id": "bd8fd6b5", + "id": "bb4f714f", "metadata": { "editable": true }, @@ -969,7 +969,7 @@ }, { "cell_type": "markdown", - "id": "b44e28ff", + "id": "9bbbd297", "metadata": { "editable": true }, @@ -979,7 +979,7 @@ }, { "cell_type": "markdown", - "id": "db216108", + "id": "4e398731", "metadata": { "editable": true }, @@ -991,7 +991,7 @@ }, { "cell_type": "markdown", - "id": "ae496c28", + "id": "99d7a7bf", "metadata": { "editable": true }, @@ -1001,7 +1001,7 @@ }, { "cell_type": "markdown", - "id": "02ebf686", + "id": "1939f1ac", "metadata": { "editable": true }, @@ -1013,7 +1013,7 @@ }, { "cell_type": "markdown", - "id": "9fb76269", + "id": "8af823c2", "metadata": { "editable": true }, @@ -1023,7 +1023,7 @@ }, { "cell_type": "markdown", - "id": "4faa3c3f", + "id": "324dbad7", "metadata": { "editable": true }, @@ -1037,7 +1037,7 @@ }, { "cell_type": "markdown", - "id": "58c9b720", + "id": "cd3a9c89", "metadata": { "editable": true }, @@ -1049,7 +1049,7 @@ }, { "cell_type": "markdown", - "id": "2b40d826", + "id": "131a6708", "metadata": { "editable": true }, @@ -1059,7 +1059,7 @@ }, { "cell_type": "markdown", - "id": "a505f2eb", + "id": "56d47a6f", "metadata": { "editable": true }, @@ -1071,7 +1071,7 @@ }, { "cell_type": "markdown", - "id": "e7a00389", + "id": "ce4c6fd3", "metadata": { "editable": true }, @@ -1081,7 +1081,7 @@ }, { "cell_type": "markdown", - "id": "a663eaeb", + "id": "e1e4dd20", "metadata": { "editable": true }, @@ -1093,7 +1093,7 @@ }, { "cell_type": "markdown", - "id": "c342c5b2", + "id": "28fb38b8", "metadata": { "editable": true }, @@ -1103,7 +1103,7 @@ }, { "cell_type": "markdown", - "id": "077068da", + "id": "c51449a8", "metadata": { "editable": true }, @@ -1115,7 +1115,7 @@ }, { "cell_type": "markdown", - "id": "0dc772ec", + "id": "f6d9733b", "metadata": { "editable": true }, @@ -1125,7 +1125,7 @@ }, { "cell_type": "markdown", - "id": "fcfd896b", + "id": "69abb29e", "metadata": { "editable": true }, @@ -1141,7 +1141,7 @@ }, { "cell_type": "markdown", - "id": "01237e2e", + "id": "78506fc0", "metadata": { "editable": true }, @@ -1153,7 +1153,7 @@ }, { "cell_type": "markdown", - "id": "1f8cec8b", + "id": "941df1b9", "metadata": { "editable": true }, @@ -1163,7 +1163,7 @@ }, { "cell_type": "markdown", - "id": "3c9588ed", + "id": "a8698a6a", "metadata": { "editable": true }, @@ -1175,7 +1175,7 @@ }, { "cell_type": "markdown", - "id": "0f448164", + "id": "c60b7f57", "metadata": { "editable": true }, @@ -1188,7 +1188,7 @@ }, { "cell_type": "markdown", - "id": "aa49a210", + "id": "cdddd567", "metadata": { "editable": true }, @@ -1200,7 +1200,7 @@ }, { "cell_type": "markdown", - "id": "4f2cdc7c", + "id": "fd7fb90e", "metadata": { "editable": true }, @@ -1210,7 +1210,7 @@ }, { "cell_type": "markdown", - "id": "f4f11c38", + "id": "39d642a9", "metadata": { "editable": true }, @@ -1222,7 +1222,7 @@ }, { "cell_type": "markdown", - "id": "8a08273f", + "id": "6237d625", "metadata": { "editable": true }, @@ -1232,7 +1232,7 @@ }, { "cell_type": "markdown", - "id": "be1179f7", + "id": "10763b41", "metadata": { "editable": true }, @@ -1244,7 +1244,7 @@ }, { "cell_type": "markdown", - "id": "18f1ca70", + "id": "5a4cd075", "metadata": { "editable": true }, @@ -1256,7 +1256,7 @@ }, { "cell_type": "markdown", - "id": "7d1f7001", + "id": "cd519e89", "metadata": { "editable": true }, @@ -1266,7 +1266,7 @@ }, { "cell_type": "markdown", - "id": "58690646", + "id": "f0003baf", "metadata": { "editable": true }, @@ -1278,7 +1278,7 @@ }, { "cell_type": "markdown", - "id": "c25b9628", + "id": "f8e8d827", "metadata": { "editable": true }, @@ -1290,7 +1290,7 @@ }, { "cell_type": "markdown", - "id": "7330eec8", + "id": "ef3471b6", "metadata": { "editable": true }, @@ -1302,7 +1302,7 @@ }, { "cell_type": "markdown", - "id": "969d3252", + "id": "3029714b", "metadata": { "editable": true }, @@ -1312,7 +1312,7 @@ }, { "cell_type": "markdown", - "id": "5c253669", + "id": "88b8a36e", "metadata": { "editable": true }, @@ -1324,7 +1324,7 @@ }, { "cell_type": "markdown", - "id": "0548637f", + "id": "b6daee50", "metadata": { "editable": true }, @@ -1334,191 +1334,7 @@ }, { "cell_type": "markdown", - "id": "e48d8dc7", - "metadata": { - "editable": true - }, - "source": [ - "## Test Function for what happens with OLS, Ridge and Lasso\n", - "\n", - "We will play around with a study of the values for the optimal\n", - "parameters $\\boldsymbol{\\beta}$ using OLS, Ridge and Lasso regression. For\n", - "OLS, you will notice as function of the noise and polynomial degree,\n", - "that the parameters $\\beta$ will fluctuate from order to order in the\n", - "polynomial fit and that for larger and larger polynomial degrees of freedom, the parameters will tend to increase in value for OLS.\n", - "\n", - "For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "e02dbcf3", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn.model_selection import train_test_split\n", - "from sklearn import linear_model\n", - "\n", - "def R2(y_data, y_model):\n", - " return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)\n", - "def MSE(y_data,y_model):\n", - " n = np.size(y_model)\n", - " return np.sum((y_data-y_model)**2)/n\n", - "\n", - "# Make data set.\n", - "n = 10000\n", - "x = np.random.rand(n)\n", - "y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)\n", - "\n", - "Maxpolydegree = 5\n", - "X = np.zeros((len(x),Maxpolydegree))\n", - "X[:,0] = 1.0\n", - "\n", - "for polydegree in range(1, Maxpolydegree+1):\n", - " for degree in range(polydegree):\n", - " X[:,degree] = x**(degree)\n", - "\n", - "\n", - "# We split the data in test and training data\n", - "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n", - "\n", - "# matrix inversion to find beta\n", - "OLSbeta = np.linalg.pinv(X_train.T @ X_train) @ X_train.T @ y_train\n", - "print(OLSbeta)\n", - "ypredictOLS = X_test @ OLSbeta\n", - "print(\"Test MSE OLS\")\n", - "print(MSE(y_test,ypredictOLS))\n", - "# Repeat now for Lasso and Ridge regression and various values of the regularization parameter using Scikit-Learn\n", - "# Decide which values of lambda to use\n", - "nlambdas = 4\n", - "MSERidgePredict = np.zeros(nlambdas)\n", - "MSELassoPredict = np.zeros(nlambdas)\n", - "lambdas = np.logspace(-3, 1, nlambdas)\n", - "for i in range(nlambdas):\n", - " lmb = lambdas[i]\n", - " # Make the fit using Ridge and Lasso\n", - " RegRidge = linear_model.Ridge(lmb,fit_intercept=False)\n", - " RegRidge.fit(X_train,y_train)\n", - " RegLasso = linear_model.Lasso(lmb,fit_intercept=False)\n", - " RegLasso.fit(X_train,y_train)\n", - " # and then make the prediction\n", - " ypredictRidge = RegRidge.predict(X_test)\n", - " ypredictLasso = RegLasso.predict(X_test)\n", - " # Compute the MSE and print it\n", - " MSERidgePredict[i] = MSE(y_test,ypredictRidge)\n", - " MSELassoPredict[i] = MSE(y_test,ypredictLasso)\n", - " print(lmb,RegRidge.coef_)\n", - " print(lmb,RegLasso.coef_)\n", - "# Now plot the results\n", - "plt.figure()\n", - "plt.plot(np.log10(lambdas), MSERidgePredict, 'b', label = 'MSE Ridge Test')\n", - "plt.plot(np.log10(lambdas), MSELassoPredict, 'r', label = 'MSE Lasso Test')\n", - "plt.xlabel('log10(lambda)')\n", - "plt.ylabel('MSE')\n", - "plt.legend()\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "293d6923", - "metadata": { - "editable": true - }, - "source": [ - "How can we understand this?" - ] - }, - { - "cell_type": "markdown", - "id": "fcefc1b2", - "metadata": { - "editable": true - }, - "source": [ - "## Rerunning the above code\n", - "\n", - "Let us write out the values of the coefficients $\\beta_i$ as functions\n", - "of the polynomial degree and noise. We will focus only on the Ridge\n", - "results and some few selected values of the hyperparameter $\\lambda$.\n", - "\n", - "If we don't include any noise and run this code for different values\n", - "of the polynomial degree, we notice that the results for $\\beta_i$ do\n", - "not show great changes from one order to the next. This is an\n", - "indication that for higher polynomial orders, our parameters become\n", - "less important.\n", - "\n", - "If we however add noise, what happens is that the polynomial fit is\n", - "trying to adjust the fit to traverse in the best possible way all data\n", - "points. This can lead to large fluctuations in the parameters\n", - "$\\beta_i$ as functions of polynomial order. It will also be reflected\n", - "in a larger value of the variance of each parameter $\\beta_i$. What\n", - "Ridge regression (and Lasso as well) are doing then is to try to\n", - "quench the fluctuations in the parameters of $\\beta_i$ which have a\n", - "large variance (normally for higher orders in the polynomial)." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "cf4592d0", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "from IPython.display import display\n", - "import matplotlib.pyplot as plt\n", - "from sklearn.model_selection import train_test_split\n", - "from sklearn import linear_model\n", - "\n", - "# Make data set.\n", - "n = 1000\n", - "x = np.random.rand(n)\n", - "y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n)\n", - "\n", - "Maxpolydegree = 5\n", - "X = np.zeros((len(x),Maxpolydegree))\n", - "X[:,0] = 1.0\n", - "\n", - "for polydegree in range(1, Maxpolydegree+1):\n", - " for degree in range(polydegree):\n", - " X[:,degree] = x**(degree)\n", - "\n", - "\n", - "# We split the data in test and training data\n", - "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n", - "\n", - "# Decide which values of lambda to use\n", - "nlambdas = 5\n", - "lambdas = np.logspace(-3, 2, nlambdas)\n", - "for i in range(nlambdas):\n", - " lmb = lambdas[i]\n", - " # Make the fit using Ridge only\n", - " RegRidge = linear_model.Ridge(lmb,fit_intercept=False)\n", - " RegRidge.fit(X_train,y_train)\n", - " # and then make the prediction\n", - " ypredictRidge = RegRidge.predict(X_test)\n", - " Coeffs = np.array(RegRidge.coef_)\n", - " BetaValues = pd.DataFrame(Coeffs)\n", - " BetaValues.columns = ['beta']\n", - " display(BetaValues)" - ] - }, - { - "cell_type": "markdown", - "id": "bf43afa2", + "id": "9d2a5293", "metadata": { "editable": true }, @@ -1537,7 +1353,7 @@ }, { "cell_type": "markdown", - "id": "fe8d4069", + "id": "77a7735b", "metadata": { "editable": true }, @@ -1565,7 +1381,7 @@ }, { "cell_type": "markdown", - "id": "dd189be3", + "id": "a78eb2b6", "metadata": { "editable": true }, @@ -1591,7 +1407,7 @@ }, { "cell_type": "markdown", - "id": "2cd833e0", + "id": "ec3ca9d2", "metadata": { "editable": true }, @@ -1608,7 +1424,7 @@ }, { "cell_type": "markdown", - "id": "84dbf216", + "id": "dee9eca5", "metadata": { "editable": true }, @@ -1628,7 +1444,7 @@ }, { "cell_type": "markdown", - "id": "056afea1", + "id": "ac9ec501", "metadata": { "editable": true }, @@ -1657,7 +1473,7 @@ }, { "cell_type": "markdown", - "id": "06d3addd", + "id": "e23a1211", "metadata": { "editable": true }, @@ -1682,7 +1498,7 @@ }, { "cell_type": "markdown", - "id": "aa7c0645", + "id": "aa8bb3d7", "metadata": { "editable": true }, @@ -1702,7 +1518,7 @@ }, { "cell_type": "markdown", - "id": "64c7a06d", + "id": "de51ff10", "metadata": { "editable": true }, @@ -1714,7 +1530,7 @@ }, { "cell_type": "markdown", - "id": "eca2c4a2", + "id": "6ea3e6be", "metadata": { "editable": true }, @@ -1724,7 +1540,7 @@ }, { "cell_type": "markdown", - "id": "7273bbd7", + "id": "a2d7baa3", "metadata": { "editable": true }, @@ -1739,7 +1555,7 @@ }, { "cell_type": "markdown", - "id": "75175080", + "id": "0306fb44", "metadata": { "editable": true }, @@ -1752,7 +1568,7 @@ }, { "cell_type": "markdown", - "id": "efc7827a", + "id": "3421f796", "metadata": { "editable": true }, @@ -1765,7 +1581,7 @@ }, { "cell_type": "markdown", - "id": "9e0cf589", + "id": "a9f82393", "metadata": { "editable": true }, @@ -1777,7 +1593,7 @@ }, { "cell_type": "markdown", - "id": "bbc835fb", + "id": "5dff3e71", "metadata": { "editable": true }, @@ -1790,7 +1606,7 @@ }, { "cell_type": "markdown", - "id": "3cb1025d", + "id": "982936a1", "metadata": { "editable": true }, @@ -1801,7 +1617,7 @@ }, { "cell_type": "markdown", - "id": "637db062", + "id": "d5d802b9", "metadata": { "editable": true }, @@ -1815,7 +1631,7 @@ }, { "cell_type": "markdown", - "id": "91eb90ca", + "id": "c2c6b5a1", "metadata": { "editable": true }, @@ -1825,7 +1641,7 @@ }, { "cell_type": "markdown", - "id": "41dcf80f", + "id": "ad883826", "metadata": { "editable": true }, @@ -1839,7 +1655,7 @@ }, { "cell_type": "markdown", - "id": "1505863d", + "id": "b7cff9a1", "metadata": { "editable": true }, @@ -1852,7 +1668,7 @@ }, { "cell_type": "markdown", - "id": "bfb61a10", + "id": "f395c150", "metadata": { "editable": true }, @@ -1865,7 +1681,7 @@ }, { "cell_type": "markdown", - "id": "99ff01ca", + "id": "e53bd542", "metadata": { "editable": true }, @@ -1875,7 +1691,7 @@ }, { "cell_type": "markdown", - "id": "779ac685", + "id": "48814a97", "metadata": { "editable": true }, @@ -1888,7 +1704,7 @@ }, { "cell_type": "markdown", - "id": "1aebe5aa", + "id": "11d6b3d0", "metadata": { "editable": true }, @@ -1898,7 +1714,7 @@ }, { "cell_type": "markdown", - "id": "d2f1901e", + "id": "e9c04393", "metadata": { "editable": true }, @@ -1911,7 +1727,7 @@ }, { "cell_type": "markdown", - "id": "a2fc0eac", + "id": "68878429", "metadata": { "editable": true }, @@ -1923,7 +1739,7 @@ }, { "cell_type": "markdown", - "id": "613167b4", + "id": "c3f0d16b", "metadata": { "editable": true }, @@ -1942,7 +1758,7 @@ }, { "cell_type": "markdown", - "id": "37c1c838", + "id": "f39e1152", "metadata": { "editable": true }, @@ -1955,7 +1771,7 @@ }, { "cell_type": "markdown", - "id": "707b0c70", + "id": "580b7c87", "metadata": { "editable": true }, @@ -1967,7 +1783,7 @@ }, { "cell_type": "markdown", - "id": "0d359fdc", + "id": "6e571c39", "metadata": { "editable": true }, @@ -1980,7 +1796,7 @@ }, { "cell_type": "markdown", - "id": "a4d7ab9b", + "id": "93257210", "metadata": { "editable": true }, @@ -2000,7 +1816,7 @@ }, { "cell_type": "markdown", - "id": "8500c84e", + "id": "38f4e783", "metadata": { "editable": true }, @@ -2023,7 +1839,7 @@ }, { "cell_type": "markdown", - "id": "d5e95153", + "id": "818ba768", "metadata": { "editable": true }, @@ -2038,7 +1854,7 @@ }, { "cell_type": "markdown", - "id": "ae89de87", + "id": "0d581327", "metadata": { "editable": true }, @@ -2050,7 +1866,7 @@ }, { "cell_type": "markdown", - "id": "df86641a", + "id": "5d05611d", "metadata": { "editable": true }, @@ -2070,7 +1886,7 @@ }, { "cell_type": "markdown", - "id": "0e6fb586", + "id": "9761ebfa", "metadata": { "editable": true }, @@ -2090,7 +1906,7 @@ }, { "cell_type": "markdown", - "id": "cba0dde9", + "id": "c32c2d41", "metadata": { "editable": true }, @@ -2114,7 +1930,7 @@ }, { "cell_type": "markdown", - "id": "a03353ff", + "id": "4b80a5d4", "metadata": { "editable": true }, @@ -2135,7 +1951,7 @@ }, { "cell_type": "markdown", - "id": "f3c80f57", + "id": "e4a1154c", "metadata": { "editable": true }, @@ -2165,7 +1981,7 @@ }, { "cell_type": "markdown", - "id": "e9a7a1fb", + "id": "8360a9e8", "metadata": { "editable": true }, @@ -2188,14 +2004,16 @@ }, { "cell_type": "code", - "execution_count": 3, - "id": "3bd31ca6", + "execution_count": 1, + "id": "7f44021f", "metadata": { "collapsed": false, "editable": true }, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import numpy as np\n", "from time import time\n", "from scipy.stats import norm\n", @@ -2226,7 +2044,7 @@ }, { "cell_type": "markdown", - "id": "401474ad", + "id": "51e8706d", "metadata": { "editable": true }, @@ -2236,7 +2054,7 @@ }, { "cell_type": "markdown", - "id": "2524316c", + "id": "d970a54f", "metadata": { "editable": true }, @@ -2246,8 +2064,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "89201846", + "execution_count": 2, + "id": "ffdc0793", "metadata": { "collapsed": false, "editable": true @@ -2267,7 +2085,7 @@ }, { "cell_type": "markdown", - "id": "3e6a04ef", + "id": "1580c90a", "metadata": { "editable": true }, @@ -2285,7 +2103,7 @@ }, { "cell_type": "markdown", - "id": "644a9cdd", + "id": "08e0c2a7", "metadata": { "editable": true }, @@ -2297,7 +2115,7 @@ }, { "cell_type": "markdown", - "id": "2ac3b829", + "id": "80072766", "metadata": { "editable": true }, @@ -2314,7 +2132,7 @@ }, { "cell_type": "markdown", - "id": "bfad28ab", + "id": "a40b71b0", "metadata": { "editable": true }, @@ -2326,7 +2144,7 @@ }, { "cell_type": "markdown", - "id": "c40c87c5", + "id": "5a13d774", "metadata": { "editable": true }, @@ -2336,7 +2154,7 @@ }, { "cell_type": "markdown", - "id": "727d76b4", + "id": "9680e502", "metadata": { "editable": true }, @@ -2348,7 +2166,7 @@ }, { "cell_type": "markdown", - "id": "395d5ad2", + "id": "dfdde330", "metadata": { "editable": true }, @@ -2365,7 +2183,7 @@ }, { "cell_type": "markdown", - "id": "4c7a1316", + "id": "46b6b1da", "metadata": { "editable": true }, @@ -2377,7 +2195,7 @@ }, { "cell_type": "markdown", - "id": "ddb2c1fa", + "id": "d17d3251", "metadata": { "editable": true }, @@ -2387,7 +2205,7 @@ }, { "cell_type": "markdown", - "id": "f738b834", + "id": "5d7d5c71", "metadata": { "editable": true }, @@ -2399,7 +2217,7 @@ }, { "cell_type": "markdown", - "id": "936b8dac", + "id": "9c1c2498", "metadata": { "editable": true }, @@ -2409,7 +2227,7 @@ }, { "cell_type": "markdown", - "id": "bf5f64fe", + "id": "c0364acd", "metadata": { "editable": true }, @@ -2421,7 +2239,7 @@ }, { "cell_type": "markdown", - "id": "a0f6bb19", + "id": "e699a03d", "metadata": { "editable": true }, @@ -2431,7 +2249,7 @@ }, { "cell_type": "markdown", - "id": "873434d6", + "id": "41096caa", "metadata": { "editable": true }, @@ -2447,7 +2265,7 @@ }, { "cell_type": "markdown", - "id": "a4b7f618", + "id": "fe00b555", "metadata": { "editable": true }, @@ -2457,8 +2275,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "606ee41d", + "execution_count": 3, + "id": "3a76eb15", "metadata": { "collapsed": false, "editable": true @@ -2523,7 +2341,7 @@ }, { "cell_type": "markdown", - "id": "e704551f", + "id": "d6107232", "metadata": { "editable": true }, @@ -2533,8 +2351,8 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "e0a7c207", + "execution_count": 4, + "id": "30727df8", "metadata": { "collapsed": false, "editable": true @@ -2591,7 +2409,7 @@ }, { "cell_type": "markdown", - "id": "e244e379", + "id": "b2c3b2d0", "metadata": { "editable": true }, @@ -2629,7 +2447,7 @@ }, { "cell_type": "markdown", - "id": "dae68b0f", + "id": "a63254aa", "metadata": { "editable": true }, @@ -2639,8 +2457,8 @@ }, { "cell_type": "code", - "execution_count": 7, - "id": "b766a0eb", + "execution_count": 5, + "id": "253b4b84", "metadata": { "collapsed": false, "editable": true @@ -2722,7 +2540,7 @@ }, { "cell_type": "markdown", - "id": "bdf8bdf7", + "id": "55d1feb3", "metadata": { "editable": true }, @@ -2747,7 +2565,7 @@ }, { "cell_type": "markdown", - "id": "1445f7db", + "id": "c41aece1", "metadata": { "editable": true }, @@ -2775,7 +2593,7 @@ }, { "cell_type": "markdown", - "id": "c3c1ffcd", + "id": "0d6c3821", "metadata": { "editable": true }, @@ -2787,8 +2605,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "id": "915c9179", + "execution_count": 6, + "id": "9bcfab0b", "metadata": { "collapsed": false, "editable": true @@ -2888,7 +2706,7 @@ }, { "cell_type": "markdown", - "id": "dd60b7b8", + "id": "898805b6", "metadata": { "editable": true }, @@ -2898,8 +2716,8 @@ }, { "cell_type": "code", - "execution_count": 9, - "id": "0ac3e6d1", + "execution_count": 7, + "id": "d1d3d505", "metadata": { "collapsed": false, "editable": true @@ -2988,7 +2806,7 @@ }, { "cell_type": "markdown", - "id": "af490576", + "id": "516216a1", "metadata": { "editable": true }, @@ -2998,7 +2816,7 @@ }, { "cell_type": "markdown", - "id": "857a0631", + "id": "71225ab2", "metadata": { "editable": true }, @@ -3010,8 +2828,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "93b9722e", + "execution_count": 8, + "id": "831753aa", "metadata": { "collapsed": false, "editable": true diff --git a/doc/src/week37/week37.do.txt b/doc/src/week37/week37.do.txt index 9a19a85dd..51aad6b24 100644 --- a/doc/src/week37/week37.do.txt +++ b/doc/src/week37/week37.do.txt @@ -588,154 +588,6 @@ which is our Lasso cost function! -!split -===== Test Function for what happens with OLS, Ridge and Lasso ===== - -We will play around with a study of the values for the optimal -parameters $\bm{\beta}$ using OLS, Ridge and Lasso regression. For -OLS, you will notice as function of the noise and polynomial degree, -that the parameters $\beta$ will fluctuate from order to order in the -polynomial fit and that for larger and larger polynomial degrees of freedom, the parameters will tend to increase in value for OLS. - -For Ridge and Lasso regression, the higher order parameters will typically be reduced, providing thereby less fluctuations from one order to another one. - -!bc pycod -import numpy as np -import matplotlib.pyplot as plt -from sklearn.model_selection import train_test_split -from sklearn import linear_model - -def R2(y_data, y_model): - return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2) -def MSE(y_data,y_model): - n = np.size(y_model) - return np.sum((y_data-y_model)**2)/n - -# Make data set. -n = 10000 -x = np.random.rand(n) -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n) - -Maxpolydegree = 5 -X = np.zeros((len(x),Maxpolydegree)) -X[:,0] = 1.0 - -for polydegree in range(1, Maxpolydegree+1): - for degree in range(polydegree): - X[:,degree] = x**(degree) - - -# We split the data in test and training data -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) - -# matrix inversion to find beta -OLSbeta = np.linalg.pinv(X_train.T @ X_train) @ X_train.T @ y_train -print(OLSbeta) -ypredictOLS = X_test @ OLSbeta -print("Test MSE OLS") -print(MSE(y_test,ypredictOLS)) -# Repeat now for Lasso and Ridge regression and various values of the regularization parameter using Scikit-Learn -# Decide which values of lambda to use -nlambdas = 4 -MSERidgePredict = np.zeros(nlambdas) -MSELassoPredict = np.zeros(nlambdas) -lambdas = np.logspace(-3, 1, nlambdas) -for i in range(nlambdas): - lmb = lambdas[i] - # Make the fit using Ridge and Lasso - RegRidge = linear_model.Ridge(lmb,fit_intercept=False) - RegRidge.fit(X_train,y_train) - RegLasso = linear_model.Lasso(lmb,fit_intercept=False) - RegLasso.fit(X_train,y_train) - # and then make the prediction - ypredictRidge = RegRidge.predict(X_test) - ypredictLasso = RegLasso.predict(X_test) - # Compute the MSE and print it - MSERidgePredict[i] = MSE(y_test,ypredictRidge) - MSELassoPredict[i] = MSE(y_test,ypredictLasso) - print(lmb,RegRidge.coef_) - print(lmb,RegLasso.coef_) -# Now plot the results -plt.figure() -plt.plot(np.log10(lambdas), MSERidgePredict, 'b', label = 'MSE Ridge Test') -plt.plot(np.log10(lambdas), MSELassoPredict, 'r', label = 'MSE Lasso Test') -plt.xlabel('log10(lambda)') -plt.ylabel('MSE') -plt.legend() -plt.show() - - -!ec - -How can we understand this? - - -!split -===== Rerunning the above code ===== - -Let us write out the values of the coefficients $\beta_i$ as functions -of the polynomial degree and noise. We will focus only on the Ridge -results and some few selected values of the hyperparameter $\lambda$. - -If we don't include any noise and run this code for different values -of the polynomial degree, we notice that the results for $\beta_i$ do -not show great changes from one order to the next. This is an -indication that for higher polynomial orders, our parameters become -less important. - -If we however add noise, what happens is that the polynomial fit is -trying to adjust the fit to traverse in the best possible way all data -points. This can lead to large fluctuations in the parameters -$\beta_i$ as functions of polynomial order. It will also be reflected -in a larger value of the variance of each parameter $\beta_i$. What -Ridge regression (and Lasso as well) are doing then is to try to -quench the fluctuations in the parameters of $\beta_i$ which have a -large variance (normally for higher orders in the polynomial). - -!bc pycod -import numpy as np -import pandas as pd -from IPython.display import display -import matplotlib.pyplot as plt -from sklearn.model_selection import train_test_split -from sklearn import linear_model - -# Make data set. -n = 1000 -x = np.random.rand(n) -y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.randn(n) - -Maxpolydegree = 5 -X = np.zeros((len(x),Maxpolydegree)) -X[:,0] = 1.0 - -for polydegree in range(1, Maxpolydegree+1): - for degree in range(polydegree): - X[:,degree] = x**(degree) - - -# We split the data in test and training data -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) - -# Decide which values of lambda to use -nlambdas = 5 -lambdas = np.logspace(-3, 2, nlambdas) -for i in range(nlambdas): - lmb = lambdas[i] - # Make the fit using Ridge only - RegRidge = linear_model.Ridge(lmb,fit_intercept=False) - RegRidge.fit(X_train,y_train) - # and then make the prediction - ypredictRidge = RegRidge.predict(X_test) - Coeffs = np.array(RegRidge.coef_) - BetaValues = pd.DataFrame(Coeffs) - BetaValues.columns = ['beta'] - display(BetaValues) - -!ec - - - !split