updated regression analysis slides
This commit is contained in:
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -251,7 +279,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2018</h4></center> <!-- date -->
|
||||
<center><h4>Sep 7, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -275,7 +303,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs008.html">9</a></li>
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -272,7 +300,7 @@ A regression model aims at finding a likelihood function \( p(y\vert \hat{x}) \)
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="._Regression-bs010.html">11</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -279,7 +307,7 @@ response is equal to \( \beta_j \).
|
||||
<li><a href="._Regression-bs010.html">11</a></li>
|
||||
<li><a href="._Regression-bs011.html">12</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs003.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -270,7 +298,7 @@ where \( \epsilon_i \) is the error in our approximation.
|
||||
<li><a href="._Regression-bs011.html">12</a></li>
|
||||
<li><a href="._Regression-bs012.html">13</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs004.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -270,7 +298,7 @@ $$
|
||||
<li><a href="._Regression-bs012.html">13</a></li>
|
||||
<li><a href="._Regression-bs013.html">14</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs005.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -292,7 +320,7 @@ $$
|
||||
<li><a href="._Regression-bs013.html">14</a></li>
|
||||
<li><a href="._Regression-bs014.html">15</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs006.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -275,7 +303,7 @@ $$
|
||||
<li><a href="._Regression-bs014.html">15</a></li>
|
||||
<li><a href="._Regression-bs015.html">16</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs007.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -281,7 +309,7 @@ The left-hand side of this equation forms know. Our error vector \( \hat{\epsilo
|
||||
<li><a href="._Regression-bs015.html">16</a></li>
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs008.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -276,7 +304,7 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs009.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -279,7 +307,7 @@ $$
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs010.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -295,7 +323,7 @@ $$
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs011.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -282,7 +310,7 @@ $$
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs012.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -284,7 +312,7 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs013.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -279,7 +307,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs014.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -284,7 +312,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs015.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -282,7 +310,7 @@ $$
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs024.html">25</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs016.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -287,7 +315,7 @@ $$
|
||||
<li><a href="._Regression-bs024.html">25</a></li>
|
||||
<li><a href="._Regression-bs025.html">26</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs017.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -280,7 +308,7 @@ $$
|
||||
<li><a href="._Regression-bs025.html">26</a></li>
|
||||
<li><a href="._Regression-bs026.html">27</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs018.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -302,7 +330,7 @@ This approach (different linear and non-linear regression) suffers often from bo
|
||||
<li><a href="._Regression-bs026.html">27</a></li>
|
||||
<li><a href="._Regression-bs027.html">28</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs019.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -295,7 +323,7 @@ We see that, as expected, a linear fit gives a seemingly (from the graph) good r
|
||||
<li><a href="._Regression-bs027.html">28</a></li>
|
||||
<li><a href="._Regression-bs028.html">29</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs020.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -286,7 +314,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs028.html">29</a></li>
|
||||
<li><a href="._Regression-bs029.html">30</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs021.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -323,7 +351,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs029.html">30</a></li>
|
||||
<li><a href="._Regression-bs030.html">31</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs022.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -277,7 +305,7 @@ where \( x \) is defined as before.
|
||||
<li><a href="._Regression-bs030.html">31</a></li>
|
||||
<li><a href="._Regression-bs031.html">32</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs023.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -268,7 +296,7 @@ have not discussed a more rigorous approach to the <b>cost</b> function.
|
||||
<li><a href="._Regression-bs031.html">32</a></li>
|
||||
<li><a href="._Regression-bs032.html">33</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs024.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -277,7 +305,7 @@ dimensionless.
|
||||
<li><a href="._Regression-bs032.html">33</a></li>
|
||||
<li><a href="._Regression-bs033.html">34</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs025.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -276,7 +304,7 @@ the \( \chi^2 \) function becomes smaller.
|
||||
<li><a href="._Regression-bs033.html">34</a></li>
|
||||
<li><a href="._Regression-bs034.html">35</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs026.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -295,7 +323,7 @@ relative error.
|
||||
<li><a href="._Regression-bs034.html">35</a></li>
|
||||
<li><a href="._Regression-bs035.html">36</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs027.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -300,7 +328,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs035.html">36</a></li>
|
||||
<li><a href="._Regression-bs036.html">37</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs028.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -272,7 +300,7 @@ this function as being similar to the \( \chi^2 \) function defined above.
|
||||
<li><a href="._Regression-bs036.html">37</a></li>
|
||||
<li><a href="._Regression-bs037.html">38</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs029.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -279,7 +307,7 @@ $$
|
||||
<li><a href="._Regression-bs037.html">38</a></li>
|
||||
<li><a href="._Regression-bs038.html">39</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs030.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -280,7 +308,7 @@ years etc.
|
||||
<li><a href="._Regression-bs038.html">39</a></li>
|
||||
<li><a href="._Regression-bs039.html">40</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs031.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -303,7 +331,7 @@ Using <b>R</b>, we can perform similar studies.
|
||||
<li><a href="._Regression-bs039.html">40</a></li>
|
||||
<li><a href="._Regression-bs040.html">41</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs032.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -286,7 +314,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs040.html">41</a></li>
|
||||
<li><a href="._Regression-bs041.html">42</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs033.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -282,7 +310,7 @@ non-random scalar. To specify the parameters of the distribution of
|
||||
<li><a href="._Regression-bs041.html">42</a></li>
|
||||
<li><a href="._Regression-bs042.html">43</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs034.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -289,7 +317,7 @@ Hence, \( Y_i \sim \mathcal{N}( \mathbf{X}_{i, \ast} \, \beta, \sigma^2) \).
|
||||
<li><a href="._Regression-bs042.html">43</a></li>
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs035.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -277,7 +305,7 @@ $$
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs036.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,84 +260,54 @@ MathJax.Hub.Config({
|
||||
<a name="part0036"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec35" class="anchor">Code examples for Ridge and Lasso Regression </h2>
|
||||
<h2 id="___sec35" class="anchor">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error, r2_score
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<span style="color: #408080; font-style: italic">#creating data with random noise</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>arange(<span style="color: #666666">50</span>)
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
delta<span style="color: #666666">=</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>uniform(<span style="color: #666666">-2.5</span>,<span style="color: #666666">2.5</span>, size<span style="color: #666666">=</span>(<span style="color: #666666">50</span>))
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>shuffle(delta)
|
||||
y <span style="color: #666666">=0.5*</span>x<span style="color: #666666">+5+</span>delta
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
|
||||
<span style="color: #408080; font-style: italic">#arranging data into 2x50 matrix</span>
|
||||
a<span style="color: #666666">=</span>np<span style="color: #666666">.</span>array(x) <span style="color: #408080; font-style: italic">#inputs</span>
|
||||
b<span style="color: #666666">=</span>np<span style="color: #666666">.</span>array(y) <span style="color: #408080; font-style: italic">#outputs</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Split into training and test</span>
|
||||
X_train<span style="color: #666666">=</span>a[:<span style="color: #666666">37</span>, np<span style="color: #666666">.</span>newaxis]
|
||||
X_test<span style="color: #666666">=</span>a[<span style="color: #666666">37</span>:, np<span style="color: #666666">.</span>newaxis]
|
||||
y_train<span style="color: #666666">=</span>b[:<span style="color: #666666">37</span>]
|
||||
y_test<span style="color: #666666">=</span>b[<span style="color: #666666">37</span>:]
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"X_train: "</span>, X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"y_train: "</span>, y_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"X_test: "</span>, X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"y_test: "</span>, y_test<span style="color: #666666">.</span>shape)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ordinary Least Squares"</span>)
|
||||
<span style="color: #408080; font-style: italic">#Add Ordinary Least Squares fit</span>
|
||||
reg<span style="color: #666666">=</span>LinearRegression()
|
||||
reg<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
pred<span style="color: #666666">=</span>reg<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Prediction Shape: "</span>, pred<span style="color: #666666">.</span>shape)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Coefficients: </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121">'</span>, reg<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #408080; font-style: italic"># The mean squared error</span>
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Mean squared error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">"</span>
|
||||
<span style="color: #666666">%</span> mean_squared_error(y_test, pred))
|
||||
<span style="color: #408080; font-style: italic"># Explained variance score: 1 is perfect prediction</span>
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Variance score: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> r2_score(y_test, pred))
|
||||
|
||||
<span style="color: #408080; font-style: italic">#plot</span>
|
||||
plt<span style="color: #666666">.</span>scatter(X_test,y_test,color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Training Data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, pred, color<span style="color: #666666">=</span><span style="color: #BA2121">'black'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Fit Line"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Regression"</span>)
|
||||
|
||||
ridge<span style="color: #666666">=</span>linear_model<span style="color: #666666">.</span>RidgeCV(alphas<span style="color: #666666">=</span>[<span style="color: #666666">0.1</span>,<span style="color: #666666">1.0</span>,<span style="color: #666666">10.0</span>])
|
||||
ridge<span style="color: #666666">.</span>fit(X_train,y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Coefficient: "</span>,ridge<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Intercept: "</span>, ridge<span style="color: #666666">.</span>intercept_)
|
||||
<span style="color: #408080; font-style: italic">#Look into graphing with Ridge fit</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Lasso"</span>)
|
||||
lasso<span style="color: #666666">=</span>linear_model<span style="color: #666666">.</span>Lasso(alpha<span style="color: #666666">=0.1</span>)
|
||||
lasso<span style="color: #666666">.</span>fit(X_train,y_train)
|
||||
predl<span style="color: #666666">=</span>lasso<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Lasso Coefficient: "</span>, lasso<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Lasso Intercept: "</span>, lasso<span style="color: #666666">.</span>intercept_)
|
||||
plt<span style="color: #666666">.</span>scatter(X_test,y_test,color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Training Data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, predl, color<span style="color: #666666">=</span><span style="color: #BA2121">'blue'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Lasso"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -335,6 +333,8 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs037.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,53 +260,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0037"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec36" class="anchor">From standard regression to Ridge regressions </h2>
|
||||
<h2 id="___sec36" class="anchor">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\tag{1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -304,6 +309,9 @@ This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigen
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs038.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,30 +260,29 @@ MathJax.Hub.Config({
|
||||
<a name="part0038"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec37" class="anchor">Fixing the singularity </h2>
|
||||
<h2 id="___sec37" class="anchor">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\tag{1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -280,6 +307,10 @@ where \( \hat{I} \) is the identity matrix.
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs039.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,117 +260,18 @@ MathJax.Hub.Config({
|
||||
<a name="part0039"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec38" class="anchor">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<h2 id="___sec38" class="anchor">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> Ridge
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> r2_score
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">4155</span>)
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
n_samples <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
|
||||
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(n_samples,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">5*</span>x<span style="color: #666666">*</span>x <span style="color: #666666">+</span> <span style="color: #666666">0.1*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(n_samples,<span style="color: #666666">1</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Centering x and y.</span>
|
||||
x_ <span style="color: #666666">=</span> x <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(x)
|
||||
y_ <span style="color: #666666">=</span> y <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y) <span style="color: #408080; font-style: italic"># beta_0 = mean(y)</span>
|
||||
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((n_samples,<span style="color: #666666">1</span>)), x, x<span style="color: #666666">**2</span>]
|
||||
X_ <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[x_, x_<span style="color: #666666">**2</span>]
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">### 1.</span>
|
||||
lmb_values <span style="color: #666666">=</span> [<span style="color: #666666">1e-4</span>, <span style="color: #666666">1e-3</span>, <span style="color: #666666">1e-2</span>, <span style="color: #666666">10</span>, <span style="color: #666666">1e2</span>, <span style="color: #666666">1e4</span>]
|
||||
num_values <span style="color: #666666">=</span> <span style="color: #008000">len</span>(lmb_values)
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Ridge-regression of centered and not centered data</span>
|
||||
beta_ridge <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #666666">3</span>,num_values))
|
||||
beta_ridge_centered <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #666666">3</span>,num_values))
|
||||
|
||||
I3 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">3</span>)
|
||||
I2 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">2</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i,lmb <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(lmb_values):
|
||||
beta_ridge[:,i] <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X<span style="color: #666666">.</span>T @ X <span style="color: #666666">+</span> lmb<span style="color: #666666">*</span>I3) @ X<span style="color: #666666">.</span>T @ y)<span style="color: #666666">.</span>flatten()
|
||||
beta_ridge_centered[<span style="color: #666666">1</span>:,i] <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X_<span style="color: #666666">.</span>T @ X_ <span style="color: #666666">+</span> lmb<span style="color: #666666">*</span>I2) @ X_<span style="color: #666666">.</span>T @ y_)<span style="color: #666666">.</span>flatten()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># sett beta_0 = np.mean(y)</span>
|
||||
beta_ridge_centered[<span style="color: #666666">0</span>,:] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean(y)
|
||||
|
||||
<span style="color: #408080; font-style: italic">## OLS (ordinary least squares) solution </span>
|
||||
beta_ls <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X<span style="color: #666666">.</span>T @ X ) @ X<span style="color: #666666">.</span>T @ y
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Evaluate the models</span>
|
||||
pred_ls <span style="color: #666666">=</span> X @ beta_ls
|
||||
pred_ridge <span style="color: #666666">=</span> X @ beta_ridge
|
||||
pred_ridge_centered <span style="color: #666666">=</span> X_ @ beta_ridge_centered[<span style="color: #666666">1</span>:] <span style="color: #666666">+</span> beta_ridge_centered[<span style="color: #666666">0</span>,:]
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Plot the results</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Sorting</span>
|
||||
sort_ind <span style="color: #666666">=</span> np<span style="color: #666666">.</span>argsort(x[:,<span style="color: #666666">0</span>])
|
||||
|
||||
x_plot <span style="color: #666666">=</span> x[sort_ind,<span style="color: #666666">0</span>]
|
||||
x_centered_plot <span style="color: #666666">=</span> x_[sort_ind,<span style="color: #666666">0</span>]
|
||||
|
||||
pred_ls_plot <span style="color: #666666">=</span> pred_ls[sort_ind,<span style="color: #666666">0</span>]
|
||||
pred_ridge_plot <span style="color: #666666">=</span> pred_ridge[sort_ind,:]
|
||||
pred_ridge_centered_plot <span style="color: #666666">=</span> pred_ridge_centered[sort_ind,:]
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plott not centered</span>
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ls_plot,label<span style="color: #666666">=</span><span style="color: #BA2121">'ls'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ridge_plot[:,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x,y,<span style="color: #BA2121">'ro'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression on un-centered data'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plott centered</span>
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_centered_plot,pred_ridge_centered_plot[:,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x_,y,<span style="color: #BA2121">'ro'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression on centered data'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic"># 2.</span>
|
||||
|
||||
pred_ridge_scikit <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((n_samples,num_values))
|
||||
<span style="color: #008000; font-weight: bold">for</span> i,lmb <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(lmb_values):
|
||||
pred_ridge_scikit[:,i] <span style="color: #666666">=</span> (Ridge(alpha<span style="color: #666666">=</span>lmb,fit_intercept<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>fit(X,y)<span style="color: #666666">.</span>predict(X))<span style="color: #666666">.</span>flatten() <span style="color: #408080; font-style: italic"># fit_intercept=False fordi bias er allerede i X</span>
|
||||
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ls_plot,label<span style="color: #666666">=</span><span style="color: #BA2121">'ls'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ridge_scikit[sort_ind,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'scikit-ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x,y,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression using scikit'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">### R2-score of the results</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'lambda = </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for scikit: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge_scikit[:,i]))
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for own code, not centered: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge[:,i]))
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for own, centered: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge_centered[:,i]))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -365,6 +294,11 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs040.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,30 +260,93 @@ MathJax.Hub.Config({
|
||||
<a name="part0040"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec39" class="anchor">Fitting vs. predicting when data is in the model class </h2>
|
||||
<h2 id="___sec39" class="anchor">An example code without the model assessment part </h2>
|
||||
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sk</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mpl</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
<span style="color: #408080; font-style: italic"># The Training Data</span>
|
||||
|
||||
N_train<span style="color: #666666">=100</span>
|
||||
|
||||
sigma_train<span style="color: #666666">=1</span>;
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train on integers</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.05</span>,<span style="color: #666666">0.95</span>,N_train)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s <span style="color: #666666">=</span> sigma_train<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_train)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#linear</span>
|
||||
y<span style="color: #666666">=2*</span>x<span style="color: #666666">+</span>s
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order</span>
|
||||
<span style="color: #408080; font-style: italic">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x,y, <span style="color: #BA2121">"o"</span>,ms<span style="color: #666666">=15</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'Training'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Regression</span>
|
||||
<span style="color: #408080; font-style: italic"># Create linear regression object</span>
|
||||
clf <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train the model using the training sets</span>
|
||||
clf<span style="color: #666666">.</span>fit(x[:, np<span style="color: #666666">.</span>newaxis], y)
|
||||
<span style="color: #408080; font-style: italic"># The coefficients</span>
|
||||
|
||||
xplot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.02</span>,<span style="color: #666666">0.98</span>,<span style="color: #666666">200</span>)
|
||||
linear_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf<span style="color: #666666">.</span>predict(xplot[:, np<span style="color: #666666">.</span>newaxis]),label<span style="color: #666666">=</span><span style="color: #BA2121">'Linear'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=3</span>)
|
||||
X <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf3 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf3<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly3<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly3_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf3<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #408080; font-style: italic">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=10</span>)
|
||||
X <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf10 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf10<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly10<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly10_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf10<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 10'</span>)
|
||||
|
||||
axes <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>gca()
|
||||
axes<span style="color: #666666">.</span>set_ylim([<span style="color: #666666">-7</span>,<span style="color: #666666">7</span>])
|
||||
|
||||
handles, labels<span style="color: #666666">=</span>axes<span style="color: #666666">.</span>get_legend_handles_labels()
|
||||
plt<span style="color: #666666">.</span>legend(handles,labels, loc<span style="color: #666666">=</span><span style="color: #BA2121">'lower center'</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x$"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>)
|
||||
Title<span style="color: #666666">=</span><span style="color: #BA2121">"$N=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(N_train)<span style="color: #666666">+</span><span style="color: #BA2121">", $\sigma=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(sigma_train)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (train)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -277,6 +368,12 @@ Summarize what you have learned about the relationship between model complexity
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs041.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -230,20 +258,51 @@ MathJax.Hub.Config({
|
||||
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
||||
|
||||
<a name="part0041"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec40" class="anchor">Fitting versus predicting when data is not in the model class </h2>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec40" class="anchor">Generating test data </h2>
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Generate Test Data</span>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
<span style="color: #408080; font-style: italic">#Number of test data</span>
|
||||
N_test<span style="color: #666666">=20</span>
|
||||
|
||||
sigma_test<span style="color: #666666">=</span>sigma_train
|
||||
|
||||
max_x<span style="color: #666666">=1.2</span>
|
||||
x_test<span style="color: #666666">=</span>max_x<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>random(N_test)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s_test <span style="color: #666666">=</span> sigma_test<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear</span>
|
||||
y_test<span style="color: #666666">=2*</span>x_test<span style="color: #666666">+</span>s_test
|
||||
<span style="color: #408080; font-style: italic">#Tenth order</span>
|
||||
<span style="color: #408080; font-style: italic">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Make design matrices for prediction</span>
|
||||
x_plot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>,max_x, <span style="color: #666666">200</span>)
|
||||
X3 <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
X10 <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure()
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_test,y_test<span style="color: #666666">.</span>transpose(), <span style="color: #BA2121">'o'</span>, ms<span style="color: #666666">=12</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'data'</span>)
|
||||
p2<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf<span style="color: #666666">.</span>predict(x_plot[:,np<span style="color: #666666">.</span>newaxis]), label<span style="color: #666666">=</span><span style="color: #BA2121">'linear'</span>)
|
||||
p3<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf3<span style="color: #666666">.</span>predict(X3), label<span style="color: #666666">=</span><span style="color: #BA2121">'3rd order'</span>)
|
||||
p10<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf10<span style="color: #666666">.</span>predict(X10), label<span style="color: #666666">=</span><span style="color: #BA2121">'10th order'</span>)
|
||||
|
||||
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">'best'</span>)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (pred.)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -264,6 +323,13 @@ Summarize what you think you learned about the relationship of knowing the true
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="._Regression-bs050.html">51</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs042.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,93 +260,14 @@ MathJax.Hub.Config({
|
||||
<a name="part0042"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec41" class="anchor">The code </h2>
|
||||
<h2 id="___sec41" class="anchor">How can we effectively evaluate the various models? </h2>
|
||||
|
||||
<p>
|
||||
In Ridge regression and the subsequent discussion of its properties
|
||||
the bias or penalty parameter is considered known or `given'. In
|
||||
practice, it is unknown and the user needs to make an informed
|
||||
decision on its value. How do we do that? Much of the same considerations apply to the Lasso method.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sk</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mpl</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
<span style="color: #408080; font-style: italic"># The Training Data</span>
|
||||
|
||||
N_train<span style="color: #666666">=100</span>
|
||||
|
||||
sigma_train<span style="color: #666666">=1</span>;
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train on integers</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.05</span>,<span style="color: #666666">0.95</span>,N_train)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s <span style="color: #666666">=</span> sigma_train<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_train)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#linear</span>
|
||||
y<span style="color: #666666">=2*</span>x<span style="color: #666666">+</span>s
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order</span>
|
||||
<span style="color: #408080; font-style: italic">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x,y, <span style="color: #BA2121">"o"</span>,ms<span style="color: #666666">=15</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'Training'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Regression</span>
|
||||
<span style="color: #408080; font-style: italic"># Create linear regression object</span>
|
||||
clf <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train the model using the training sets</span>
|
||||
clf<span style="color: #666666">.</span>fit(x[:, np<span style="color: #666666">.</span>newaxis], y)
|
||||
<span style="color: #408080; font-style: italic"># The coefficients</span>
|
||||
|
||||
xplot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.02</span>,<span style="color: #666666">0.98</span>,<span style="color: #666666">200</span>)
|
||||
linear_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf<span style="color: #666666">.</span>predict(xplot[:, np<span style="color: #666666">.</span>newaxis]),label<span style="color: #666666">=</span><span style="color: #BA2121">'Linear'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=3</span>)
|
||||
X <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf3 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf3<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly3<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly3_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf3<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #408080; font-style: italic">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=10</span>)
|
||||
X <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf10 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf10<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly10<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly10_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf10<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 10'</span>)
|
||||
|
||||
axes <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>gca()
|
||||
axes<span style="color: #666666">.</span>set_ylim([<span style="color: #666666">-7</span>,<span style="color: #666666">7</span>])
|
||||
|
||||
handles, labels<span style="color: #666666">=</span>axes<span style="color: #666666">.</span>get_legend_handles_labels()
|
||||
plt<span style="color: #666666">.</span>legend(handles,labels, loc<span style="color: #666666">=</span><span style="color: #BA2121">'lower center'</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x$"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>)
|
||||
Title<span style="color: #666666">=</span><span style="color: #BA2121">"$N=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(N_train)<span style="color: #666666">+</span><span style="color: #BA2121">", $\sigma=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(sigma_train)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (train)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -338,6 +287,14 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="._Regression-bs050.html">51</a></li>
|
||||
<li><a href="._Regression-bs051.html">52</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs043.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -230,57 +258,85 @@ MathJax.Hub.Config({
|
||||
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
||||
|
||||
<a name="part0043"></a>
|
||||
<!-- !split -->
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec42" class="anchor">Code examples for Ridge and Lasso Regression </h2>
|
||||
|
||||
<h2 id="___sec42" class="anchor">Generating test data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Generate Test Data</span>
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error, r2_score
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Number of test data</span>
|
||||
N_test<span style="color: #666666">=20</span>
|
||||
<span style="color: #408080; font-style: italic">#creating data with random noise</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>arange(<span style="color: #666666">50</span>)
|
||||
|
||||
sigma_test<span style="color: #666666">=</span>sigma_train
|
||||
delta<span style="color: #666666">=</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>uniform(<span style="color: #666666">-2.5</span>,<span style="color: #666666">2.5</span>, size<span style="color: #666666">=</span>(<span style="color: #666666">50</span>))
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>shuffle(delta)
|
||||
y <span style="color: #666666">=0.5*</span>x<span style="color: #666666">+5+</span>delta
|
||||
|
||||
max_x<span style="color: #666666">=1.2</span>
|
||||
x_test<span style="color: #666666">=</span>max_x<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>random(N_test)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s_test <span style="color: #666666">=</span> sigma_test<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_test)
|
||||
<span style="color: #408080; font-style: italic">#arranging data into 2x50 matrix</span>
|
||||
a<span style="color: #666666">=</span>np<span style="color: #666666">.</span>array(x) <span style="color: #408080; font-style: italic">#inputs</span>
|
||||
b<span style="color: #666666">=</span>np<span style="color: #666666">.</span>array(y) <span style="color: #408080; font-style: italic">#outputs</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear</span>
|
||||
y_test<span style="color: #666666">=2*</span>x_test<span style="color: #666666">+</span>s_test
|
||||
<span style="color: #408080; font-style: italic">#Tenth order</span>
|
||||
<span style="color: #408080; font-style: italic">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
<span style="color: #408080; font-style: italic">#Split into training and test</span>
|
||||
X_train<span style="color: #666666">=</span>a[:<span style="color: #666666">37</span>, np<span style="color: #666666">.</span>newaxis]
|
||||
X_test<span style="color: #666666">=</span>a[<span style="color: #666666">37</span>:, np<span style="color: #666666">.</span>newaxis]
|
||||
y_train<span style="color: #666666">=</span>b[:<span style="color: #666666">37</span>]
|
||||
y_test<span style="color: #666666">=</span>b[<span style="color: #666666">37</span>:]
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Make design matrices for prediction</span>
|
||||
x_plot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>,max_x, <span style="color: #666666">200</span>)
|
||||
X3 <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
X10 <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"X_train: "</span>, X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"y_train: "</span>, y_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"X_test: "</span>, X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"y_test: "</span>, y_test<span style="color: #666666">.</span>shape)
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure()
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_test,y_test<span style="color: #666666">.</span>transpose(), <span style="color: #BA2121">'o'</span>, ms<span style="color: #666666">=12</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'data'</span>)
|
||||
p2<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf<span style="color: #666666">.</span>predict(x_plot[:,np<span style="color: #666666">.</span>newaxis]), label<span style="color: #666666">=</span><span style="color: #BA2121">'linear'</span>)
|
||||
p3<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf3<span style="color: #666666">.</span>predict(X3), label<span style="color: #666666">=</span><span style="color: #BA2121">'3rd order'</span>)
|
||||
p10<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf10<span style="color: #666666">.</span>predict(X10), label<span style="color: #666666">=</span><span style="color: #BA2121">'10th order'</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ordinary Least Squares"</span>)
|
||||
<span style="color: #408080; font-style: italic">#Add Ordinary Least Squares fit</span>
|
||||
reg<span style="color: #666666">=</span>LinearRegression()
|
||||
reg<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
pred<span style="color: #666666">=</span>reg<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Prediction Shape: "</span>, pred<span style="color: #666666">.</span>shape)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Coefficients: </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121">'</span>, reg<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #408080; font-style: italic"># The mean squared error</span>
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Mean squared error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">"</span>
|
||||
<span style="color: #666666">%</span> mean_squared_error(y_test, pred))
|
||||
<span style="color: #408080; font-style: italic"># Explained variance score: 1 is perfect prediction</span>
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Variance score: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> r2_score(y_test, pred))
|
||||
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">'best'</span>)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (pred.)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
<span style="color: #408080; font-style: italic">#plot</span>
|
||||
plt<span style="color: #666666">.</span>scatter(X_test,y_test,color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Training Data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, pred, color<span style="color: #666666">=</span><span style="color: #BA2121">'black'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Fit Line"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Filename</span>
|
||||
<span style="color: #408080; font-style: italic">#filename_test=Title+"pred-linear.pdf"</span>
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order Filename</span>
|
||||
<span style="color: #408080; font-style: italic">#filename_test=Title+"pred-o10.pdf"</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.savefig(filename_test)</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.ylim((-6,12))</span>
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Regression"</span>)
|
||||
|
||||
ridge<span style="color: #666666">=</span>linear_model<span style="color: #666666">.</span>RidgeCV(alphas<span style="color: #666666">=</span>[<span style="color: #666666">0.1</span>,<span style="color: #666666">1.0</span>,<span style="color: #666666">10.0</span>])
|
||||
ridge<span style="color: #666666">.</span>fit(X_train,y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Coefficient: "</span>,ridge<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Ridge Intercept: "</span>, ridge<span style="color: #666666">.</span>intercept_)
|
||||
<span style="color: #408080; font-style: italic">#Look into graphing with Ridge fit</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"------------------------------------"</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span> (<span style="color: #BA2121">"Lasso"</span>)
|
||||
lasso<span style="color: #666666">=</span>linear_model<span style="color: #666666">.</span>Lasso(alpha<span style="color: #666666">=0.1</span>)
|
||||
lasso<span style="color: #666666">.</span>fit(X_train,y_train)
|
||||
predl<span style="color: #666666">=</span>lasso<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Lasso Coefficient: "</span>, lasso<span style="color: #666666">.</span>coef_)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Lasso Intercept: "</span>, lasso<span style="color: #666666">.</span>intercept_)
|
||||
plt<span style="color: #666666">.</span>scatter(X_test,y_test,color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Training Data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, predl, color<span style="color: #666666">=</span><span style="color: #BA2121">'blue'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Lasso"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
@@ -300,6 +356,15 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li class="active"><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="._Regression-bs050.html">51</a></li>
|
||||
<li><a href="._Regression-bs051.html">52</a></li>
|
||||
<li><a href="._Regression-bs052.html">53</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs044.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,8 +260,117 @@ MathJax.Hub.Config({
|
||||
<a name="part0044"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec43" class="anchor">Lasso regression </h2>
|
||||
<h2 id="___sec43" class="anchor">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> Ridge
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> r2_score
|
||||
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">4155</span>)
|
||||
|
||||
n_samples <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
|
||||
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(n_samples,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">5*</span>x<span style="color: #666666">*</span>x <span style="color: #666666">+</span> <span style="color: #666666">0.1*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(n_samples,<span style="color: #666666">1</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Centering x and y.</span>
|
||||
x_ <span style="color: #666666">=</span> x <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(x)
|
||||
y_ <span style="color: #666666">=</span> y <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y) <span style="color: #408080; font-style: italic"># beta_0 = mean(y)</span>
|
||||
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((n_samples,<span style="color: #666666">1</span>)), x, x<span style="color: #666666">**2</span>]
|
||||
X_ <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[x_, x_<span style="color: #666666">**2</span>]
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">### 1.</span>
|
||||
lmb_values <span style="color: #666666">=</span> [<span style="color: #666666">1e-4</span>, <span style="color: #666666">1e-3</span>, <span style="color: #666666">1e-2</span>, <span style="color: #666666">10</span>, <span style="color: #666666">1e2</span>, <span style="color: #666666">1e4</span>]
|
||||
num_values <span style="color: #666666">=</span> <span style="color: #008000">len</span>(lmb_values)
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Ridge-regression of centered and not centered data</span>
|
||||
beta_ridge <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #666666">3</span>,num_values))
|
||||
beta_ridge_centered <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #666666">3</span>,num_values))
|
||||
|
||||
I3 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">3</span>)
|
||||
I2 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">2</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i,lmb <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(lmb_values):
|
||||
beta_ridge[:,i] <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X<span style="color: #666666">.</span>T @ X <span style="color: #666666">+</span> lmb<span style="color: #666666">*</span>I3) @ X<span style="color: #666666">.</span>T @ y)<span style="color: #666666">.</span>flatten()
|
||||
beta_ridge_centered[<span style="color: #666666">1</span>:,i] <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X_<span style="color: #666666">.</span>T @ X_ <span style="color: #666666">+</span> lmb<span style="color: #666666">*</span>I2) @ X_<span style="color: #666666">.</span>T @ y_)<span style="color: #666666">.</span>flatten()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># sett beta_0 = np.mean(y)</span>
|
||||
beta_ridge_centered[<span style="color: #666666">0</span>,:] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean(y)
|
||||
|
||||
<span style="color: #408080; font-style: italic">## OLS (ordinary least squares) solution </span>
|
||||
beta_ls <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv( X<span style="color: #666666">.</span>T @ X ) @ X<span style="color: #666666">.</span>T @ y
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Evaluate the models</span>
|
||||
pred_ls <span style="color: #666666">=</span> X @ beta_ls
|
||||
pred_ridge <span style="color: #666666">=</span> X @ beta_ridge
|
||||
pred_ridge_centered <span style="color: #666666">=</span> X_ @ beta_ridge_centered[<span style="color: #666666">1</span>:] <span style="color: #666666">+</span> beta_ridge_centered[<span style="color: #666666">0</span>,:]
|
||||
|
||||
<span style="color: #408080; font-style: italic">## Plot the results</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Sorting</span>
|
||||
sort_ind <span style="color: #666666">=</span> np<span style="color: #666666">.</span>argsort(x[:,<span style="color: #666666">0</span>])
|
||||
|
||||
x_plot <span style="color: #666666">=</span> x[sort_ind,<span style="color: #666666">0</span>]
|
||||
x_centered_plot <span style="color: #666666">=</span> x_[sort_ind,<span style="color: #666666">0</span>]
|
||||
|
||||
pred_ls_plot <span style="color: #666666">=</span> pred_ls[sort_ind,<span style="color: #666666">0</span>]
|
||||
pred_ridge_plot <span style="color: #666666">=</span> pred_ridge[sort_ind,:]
|
||||
pred_ridge_centered_plot <span style="color: #666666">=</span> pred_ridge_centered[sort_ind,:]
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plott not centered</span>
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ls_plot,label<span style="color: #666666">=</span><span style="color: #BA2121">'ls'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ridge_plot[:,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x,y,<span style="color: #BA2121">'ro'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression on un-centered data'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plott centered</span>
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_centered_plot,pred_ridge_centered_plot[:,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x_,y,<span style="color: #BA2121">'ro'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression on centered data'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic"># 2.</span>
|
||||
|
||||
pred_ridge_scikit <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((n_samples,num_values))
|
||||
<span style="color: #008000; font-weight: bold">for</span> i,lmb <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(lmb_values):
|
||||
pred_ridge_scikit[:,i] <span style="color: #666666">=</span> (Ridge(alpha<span style="color: #666666">=</span>lmb,fit_intercept<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>fit(X,y)<span style="color: #666666">.</span>predict(X))<span style="color: #666666">.</span>flatten() <span style="color: #408080; font-style: italic"># fit_intercept=False fordi bias er allerede i X</span>
|
||||
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ls_plot,label<span style="color: #666666">=</span><span style="color: #BA2121">'ls'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
plt<span style="color: #666666">.</span>plot(x_plot,pred_ridge_scikit[sort_ind,i],label<span style="color: #666666">=</span><span style="color: #BA2121">'scikit-ridge, lmb=</span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(x,y,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">'linear regression using scikit'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">### R2-score of the results</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_values):
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'lambda = </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>lmb_values[i])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for scikit: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge_scikit[:,i]))
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for own code, not centered: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge[:,i]))
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'r2 for own, centered: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121">'</span><span style="color: #666666">%</span>r2_score(y,pred_ridge_centered[:,i]))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -251,6 +388,14 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li class="active"><a href="._Regression-bs044.html">45</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="._Regression-bs050.html">51</a></li>
|
||||
<li><a href="._Regression-bs051.html">52</a></li>
|
||||
<li><a href="._Regression-bs052.html">53</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs045.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -232,8 +260,25 @@ MathJax.Hub.Config({
|
||||
<a name="part0045"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec44" class="anchor">Logistic regression </h2>
|
||||
<h2 id="___sec44" class="anchor">Resampling methods </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
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.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -249,6 +294,15 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs043.html">44</a></li>
|
||||
<li><a href="._Regression-bs044.html">45</a></li>
|
||||
<li class="active"><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs046.html">47</a></li>
|
||||
<li><a href="._Regression-bs047.html">48</a></li>
|
||||
<li><a href="._Regression-bs048.html">49</a></li>
|
||||
<li><a href="._Regression-bs049.html">50</a></li>
|
||||
<li><a href="._Regression-bs050.html">51</a></li>
|
||||
<li><a href="._Regression-bs051.html">52</a></li>
|
||||
<li><a href="._Regression-bs052.html">53</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs046.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -110,31 +110,51 @@ Automatically generated HTML file from DocOnce source
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -207,16 +227,24 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs033.html#___sec32" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs034.html#___sec33" style="font-size: 80%;">Expectation value and variance</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs035.html#___sec34" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">The code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">Lasso regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Logistic regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs036.html#___sec35" style="font-size: 80%;">From standard regression to Ridge regressions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs037.html#___sec36" style="font-size: 80%;">Fixing the singularity</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs038.html#___sec37" style="font-size: 80%;">Fitting vs. predicting when data is in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs039.html#___sec38" style="font-size: 80%;">Fitting versus predicting when data is not in the model class</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs040.html#___sec39" style="font-size: 80%;">An example code without the model assessment part</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs041.html#___sec40" style="font-size: 80%;">Generating test data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs042.html#___sec41" style="font-size: 80%;">How can we effectively evaluate the various models?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs043.html#___sec42" style="font-size: 80%;">Code examples for Ridge and Lasso Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs044.html#___sec43" style="font-size: 80%;">A second-order polynomial with Ridge and Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs045.html#___sec44" style="font-size: 80%;">Resampling methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs046.html#___sec45" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs047.html#___sec46" style="font-size: 80%;">Log-likelihood</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs048.html#___sec47" style="font-size: 80%;">Cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs049.html#___sec48" style="font-size: 80%;">Computationally expensive</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs050.html#___sec49" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs051.html#___sec50" style="font-size: 80%;">How to set up the cross-validation for Ridge and/or Lasso</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs052.html#___sec51" style="font-size: 80%;">Predicted Residual Error Sum of Squares</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs053.html#___sec52" style="font-size: 80%;">Bootstrap</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -251,7 +279,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2018</h4></center> <!-- date -->
|
||||
<center><h4>Sep 7, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -275,7 +303,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs008.html">9</a></li>
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs045.html">46</a></li>
|
||||
<li><a href="._Regression-bs053.html">54</a></li>
|
||||
<li><a href="._Regression-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Sep 6, 2018</h4></center> <!-- date -->
|
||||
<center><h4>Sep 7, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -1282,7 +1282,287 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec35">Code examples for Ridge and Lasso Regression </h2>
|
||||
<h2 id="___sec35">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec36">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\tag{1}
|
||||
\end{align}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
<p> <br>
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec37">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<p><li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<p><li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<p><li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<p><li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
<p>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec38">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
|
||||
<ol>
|
||||
<p><li> Do better fits lead to better predictions?</li>
|
||||
<p><li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
<p>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec39">An example code without the model assessment part </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">sk</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mpl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
<span style="color: #228B22"># The Training Data</span>
|
||||
|
||||
N_train=<span style="color: #B452CD">100</span>
|
||||
|
||||
sigma_train=<span style="color: #B452CD">1</span>;
|
||||
|
||||
<span style="color: #228B22"># Train on integers</span>
|
||||
x=np.linspace(<span style="color: #B452CD">0.05</span>,<span style="color: #B452CD">0.95</span>,N_train)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s = sigma_train*np.random.randn(N_train)
|
||||
|
||||
<span style="color: #228B22">#linear</span>
|
||||
y=<span style="color: #B452CD">2</span>*x+s
|
||||
|
||||
<span style="color: #228B22">#Tenth Order</span>
|
||||
<span style="color: #228B22">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1=plt.plot(x,y, <span style="color: #CD5555">"o"</span>,ms=<span style="color: #B452CD">15</span>, label=<span style="color: #CD5555">'Training'</span>)
|
||||
|
||||
<span style="color: #228B22">#Linear Regression</span>
|
||||
<span style="color: #228B22"># Create linear regression object</span>
|
||||
clf = linear_model.LinearRegression()
|
||||
|
||||
<span style="color: #228B22"># Train the model using the training sets</span>
|
||||
clf.fit(x[:, np.newaxis], y)
|
||||
<span style="color: #228B22"># The coefficients</span>
|
||||
|
||||
xplot=np.linspace(<span style="color: #B452CD">0.02</span>,<span style="color: #B452CD">0.98</span>,<span style="color: #B452CD">200</span>)
|
||||
linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label=<span style="color: #CD5555">'Linear'</span>)
|
||||
|
||||
<span style="color: #228B22">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 = PolynomialFeatures(degree=<span style="color: #B452CD">3</span>)
|
||||
X = poly3.fit_transform(x[:,np.newaxis])
|
||||
clf3 = linear_model.LinearRegression()
|
||||
clf3.fit(X,y)
|
||||
|
||||
|
||||
Xplot=poly3.fit_transform(xplot[:,np.newaxis])
|
||||
poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label=<span style="color: #CD5555">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #228B22">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #228B22">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #228B22">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #228B22">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 = PolynomialFeatures(degree=<span style="color: #B452CD">10</span>)
|
||||
X = poly10.fit_transform(x[:,np.newaxis])
|
||||
clf10 = linear_model.LinearRegression()
|
||||
clf10.fit(X,y)
|
||||
|
||||
Xplot=poly10.fit_transform(xplot[:,np.newaxis])
|
||||
poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label=<span style="color: #CD5555">'Poly 10'</span>)
|
||||
|
||||
axes = plt.gca()
|
||||
axes.set_ylim([-<span style="color: #B452CD">7</span>,<span style="color: #B452CD">7</span>])
|
||||
|
||||
handles, labels=axes.get_legend_handles_labels()
|
||||
plt.legend(handles,labels, loc=<span style="color: #CD5555">'lower center'</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">"$x$"</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">"$y$"</span>)
|
||||
Title=<span style="color: #CD5555">"$N=$"</span>+<span style="color: #658b00">str</span>(N_train)+<span style="color: #CD5555">", $\sigma=$"</span>+<span style="color: #658b00">str</span>(sigma_train)
|
||||
plt.title(Title+<span style="color: #CD5555">" (train)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec40">Generating test data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #228B22">#Number of test data</span>
|
||||
N_test=<span style="color: #B452CD">20</span>
|
||||
|
||||
sigma_test=sigma_train
|
||||
|
||||
max_x=<span style="color: #B452CD">1.2</span>
|
||||
x_test=max_x*np.random.random(N_test)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s_test = sigma_test*np.random.randn(N_test)
|
||||
|
||||
<span style="color: #228B22">#Linear</span>
|
||||
y_test=<span style="color: #B452CD">2</span>*x_test+s_test
|
||||
<span style="color: #228B22">#Tenth order</span>
|
||||
<span style="color: #228B22">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #228B22">#Make design matrices for prediction</span>
|
||||
x_plot=np.linspace(<span style="color: #B452CD">0</span>,max_x, <span style="color: #B452CD">200</span>)
|
||||
X3 = poly3.fit_transform(x_plot[:,np.newaxis])
|
||||
X10 = poly10.fit_transform(x_plot[:,np.newaxis])
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
fig = plt.figure()
|
||||
p1=plt.plot(x_test,y_test.transpose(), <span style="color: #CD5555">'o'</span>, ms=<span style="color: #B452CD">12</span>, label=<span style="color: #CD5555">'data'</span>)
|
||||
p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label=<span style="color: #CD5555">'linear'</span>)
|
||||
p3=plt.plot(x_plot,clf3.predict(X3), label=<span style="color: #CD5555">'3rd order'</span>)
|
||||
p10=plt.plot(x_plot,clf10.predict(X10), label=<span style="color: #CD5555">'10th order'</span>)
|
||||
|
||||
|
||||
plt.legend(loc=<span style="color: #B452CD">2</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'$y$'</span>)
|
||||
plt.legend(loc=<span style="color: #CD5555">'best'</span>)
|
||||
plt.title(Title+<span style="color: #CD5555">" (pred.)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec41">How can we effectively evaluate the various models? </h2>
|
||||
|
||||
<p>
|
||||
In Ridge regression and the subsequent discussion of its properties
|
||||
the bias or penalty parameter is considered known or `given'. In
|
||||
practice, it is unknown and the user needs to make an informed
|
||||
decision on its value. How do we do that? Much of the same considerations apply to the Lasso method.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec42">Code examples for Ridge and Lasso Regression </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1364,94 +1644,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec36">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec37">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\tag{1}
|
||||
\end{align}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
<p> <br>
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec38">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<h2 id="___sec43">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1566,201 +1759,233 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec39">Fitting vs. predicting when data is in the model class </h2>
|
||||
<h2 id="___sec44">Resampling methods </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
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.
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec45">Resampling approaches can be computationally expensive </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
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.
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec46">Log-likelihood </h2>
|
||||
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
A popular strategy is to choose a penalty parameter that yields a good
|
||||
but parsimonious model. Information criteria measure the balance
|
||||
between model fit and model complexity. One possibility is Aikaike's
|
||||
information criterion (AIC).
|
||||
The AIC measures model fit by the log-likelihood
|
||||
and model complexity is measured by the number of parameters used by
|
||||
the model. The number of model parameters in regular regression simply
|
||||
corresponds to the number of covariates in the model. Or, by the
|
||||
degrees of freedom consumed by the model, which is equivalent to the
|
||||
trace of the hat matrix. For ridge regression it thus seems natural to
|
||||
define model complexity analogously by the trace of the ridge hat
|
||||
matrix. This yields the AIC for the linear regression model with ridge
|
||||
estimates:
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\mbox{AIC}(\lambda) & = 2 \, p - 2 \log(\hat{L})
|
||||
\\
|
||||
& = 2 \, \mbox{tr} [\mathbf{H}(\lambda)] - 2 \log\{L[\hat{\beta}(\lambda), \hat{\sigma}^2(\lambda)]\}
|
||||
\\
|
||||
& = 2 \, \sum_{j=1}^p \frac{d_{jj}^2}{d_{jj}^2 + \lambda}
|
||||
+ 2 n \, \log[\sqrt{2 \, \pi} \, \hat{\sigma}(\lambda)] + \frac{1}{\hat{\sigma}^2(\lambda)} \sum_{i=1}^n [y_i - \mathbf{X}_{i, \ast} \, \hat{\beta}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
The value of \( \lambda \) which minimizes \( \mbox{AIC}(\lambda) \) corresponds to the `optimal' balance of model complexity and overfitting.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec47">Cross-validation </h2>
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
Instead of choosing the penalty parameter to balance model fit with
|
||||
model complexity, cross-validation requires it (i.e. the penalty
|
||||
parameter) to yield a model with good prediction
|
||||
performance. Commonly, this performance is evaluated on novel
|
||||
data. Novel data need not be easy to come by and one has to make do
|
||||
with the data at hand. The setting of `original' and novel data is
|
||||
then mimicked by sample splitting: the data set is divided into two
|
||||
(groups of samples). One of these two data sets, called the <em>training
|
||||
set</em>, plays the role of `original' data on which the model is
|
||||
built. The second of these data sets, called the <em>test set</em>, plays the
|
||||
role of the `novel' data and is used to evaluate the prediction
|
||||
performance (often operationalized as the log-likelihood or the
|
||||
prediction error or its square or the R2 score) of the model built on the training data set. This
|
||||
procedure (model building and prediction evaluation on training and
|
||||
test set, respectively) is done for a collection of possible penalty
|
||||
parameter choices. The penalty parameter that yields the model with
|
||||
the best prediction performance is to be preferred. The thus obtained
|
||||
performance evaluation depends on the actual split of the data set. To
|
||||
remove this dependence the data set is split many times into a
|
||||
training and test set. For each split the model parameters are
|
||||
estimated for all choices of \( \lambda \) using the training data and
|
||||
estimated parameters are evaluated on the corresponding test set. The
|
||||
penalty parameter that on average over the test sets performs best (in
|
||||
some sense) is then selected.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec48">Computationally expensive </h2>
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
The validation set approach is conceptually simple and is easy to implement. But it has two potential drawbacks:
|
||||
|
||||
<ul>
|
||||
<p><li> The validation estimate of the test error rate can be highly variable, depending on precisely which observations are included in the training set and which observations are included in the validation set.</li>
|
||||
<p><li> In the validation approach, only a subset of the observations, those that are included in the training set rather than in the validation set are used to fit the model. Since statistical methods tend to perform worse when trained on fewer observations, this suggests that the validation set error rate may tend to overestimate the test error rate for the model fit on the entire data set.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec49">Various steps in cross-validation </h2>
|
||||
|
||||
<p>
|
||||
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).
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec50">How to set up the cross-validation for Ridge and/or Lasso </h2>
|
||||
|
||||
<ol>
|
||||
<p><li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<p><li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<p><li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<p><li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
<p><li> Define a range of interest for the penalty parameter.</li>
|
||||
<p><li> Divide the data set into training and test set comprising samples \( \{1, \ldots, n\} \setminus i \) and \( \{ i \} \), respectively.</li>
|
||||
<p><li> Fit the linear regression model by means of ridge estimation for each \( \lambda \) in the grid using the training set as</li>
|
||||
</ol>
|
||||
<p>
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{\beta}_{-i}(\lambda) & = ( \hat{X}_{-i, \ast}^{\top}
|
||||
\hat{X}_{-i, \ast} + \lambda \hat{I}_{pp})^{-1}
|
||||
\hat{X}_{-i, \ast}^{\top} \hat{y}_{-i}
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec40">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
and the corresponding estimate of the error variance \( \hat{\sigma}_{-i}^2(\lambda) \).
|
||||
|
||||
<ol>
|
||||
<p><li> Do better fits lead to better predictions?</li>
|
||||
<p><li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
<p><li> Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \hat{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.</li>
|
||||
<p><li> Repeat steps 1) to 3) such that each sample plays the role of the test set once.</li>
|
||||
<p><li> Average the prediction performances of the test sets at each grid point of the penalty bias/parameter</li>
|
||||
</ol>
|
||||
<p>
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{1}{n} \sum_{i = 1}^n \log\{L[Y_i, \mathbf{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\}.
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
The quantity above is called the <em>cross-validated log-likelihood</em>. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data.
|
||||
|
||||
<ol>
|
||||
<p><li> The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.</li>
|
||||
</ol>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec41">The code </h2>
|
||||
<h2 id="___sec51">Predicted Residual Error Sum of Squares </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Another approach in the LOOCV scheme is to the use the so-called Predicted Residual Error Sum of Squares (PRESS).
|
||||
|
||||
<p>
|
||||
We can define the optimal penalty parameter to minimize
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
\lambda_{\mbox{{\tiny opt}}} = \arg \min_{\lambda} \frac{1}{n} \sum_{i=1}^n [y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">sk</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mpl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
<span style="color: #228B22"># The Training Data</span>
|
||||
|
||||
N_train=<span style="color: #B452CD">100</span>
|
||||
|
||||
sigma_train=<span style="color: #B452CD">1</span>;
|
||||
|
||||
<span style="color: #228B22"># Train on integers</span>
|
||||
x=np.linspace(<span style="color: #B452CD">0.05</span>,<span style="color: #B452CD">0.95</span>,N_train)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s = sigma_train*np.random.randn(N_train)
|
||||
|
||||
<span style="color: #228B22">#linear</span>
|
||||
y=<span style="color: #B452CD">2</span>*x+s
|
||||
|
||||
<span style="color: #228B22">#Tenth Order</span>
|
||||
<span style="color: #228B22">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1=plt.plot(x,y, <span style="color: #CD5555">"o"</span>,ms=<span style="color: #B452CD">15</span>, label=<span style="color: #CD5555">'Training'</span>)
|
||||
|
||||
<span style="color: #228B22">#Linear Regression</span>
|
||||
<span style="color: #228B22"># Create linear regression object</span>
|
||||
clf = linear_model.LinearRegression()
|
||||
|
||||
<span style="color: #228B22"># Train the model using the training sets</span>
|
||||
clf.fit(x[:, np.newaxis], y)
|
||||
<span style="color: #228B22"># The coefficients</span>
|
||||
|
||||
xplot=np.linspace(<span style="color: #B452CD">0.02</span>,<span style="color: #B452CD">0.98</span>,<span style="color: #B452CD">200</span>)
|
||||
linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label=<span style="color: #CD5555">'Linear'</span>)
|
||||
|
||||
<span style="color: #228B22">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 = PolynomialFeatures(degree=<span style="color: #B452CD">3</span>)
|
||||
X = poly3.fit_transform(x[:,np.newaxis])
|
||||
clf3 = linear_model.LinearRegression()
|
||||
clf3.fit(X,y)
|
||||
|
||||
|
||||
Xplot=poly3.fit_transform(xplot[:,np.newaxis])
|
||||
poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label=<span style="color: #CD5555">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #228B22">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #228B22">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #228B22">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #228B22">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 = PolynomialFeatures(degree=<span style="color: #B452CD">10</span>)
|
||||
X = poly10.fit_transform(x[:,np.newaxis])
|
||||
clf10 = linear_model.LinearRegression()
|
||||
clf10.fit(X,y)
|
||||
|
||||
Xplot=poly10.fit_transform(xplot[:,np.newaxis])
|
||||
poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label=<span style="color: #CD5555">'Poly 10'</span>)
|
||||
|
||||
axes = plt.gca()
|
||||
axes.set_ylim([-<span style="color: #B452CD">7</span>,<span style="color: #B452CD">7</span>])
|
||||
|
||||
handles, labels=axes.get_legend_handles_labels()
|
||||
plt.legend(handles,labels, loc=<span style="color: #CD5555">'lower center'</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">"$x$"</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">"$y$"</span>)
|
||||
Title=<span style="color: #CD5555">"$N=$"</span>+<span style="color: #658b00">str</span>(N_train)+<span style="color: #CD5555">", $\sigma=$"</span>+<span style="color: #658b00">str</span>(sigma_train)
|
||||
plt.title(Title+<span style="color: #CD5555">" (train)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec42">Generating test data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #228B22">#Number of test data</span>
|
||||
N_test=<span style="color: #B452CD">20</span>
|
||||
|
||||
sigma_test=sigma_train
|
||||
|
||||
max_x=<span style="color: #B452CD">1.2</span>
|
||||
x_test=max_x*np.random.random(N_test)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s_test = sigma_test*np.random.randn(N_test)
|
||||
|
||||
<span style="color: #228B22">#Linear</span>
|
||||
y_test=<span style="color: #B452CD">2</span>*x_test+s_test
|
||||
<span style="color: #228B22">#Tenth order</span>
|
||||
<span style="color: #228B22">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #228B22">#Make design matrices for prediction</span>
|
||||
x_plot=np.linspace(<span style="color: #B452CD">0</span>,max_x, <span style="color: #B452CD">200</span>)
|
||||
X3 = poly3.fit_transform(x_plot[:,np.newaxis])
|
||||
X10 = poly10.fit_transform(x_plot[:,np.newaxis])
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
fig = plt.figure()
|
||||
p1=plt.plot(x_test,y_test.transpose(), <span style="color: #CD5555">'o'</span>, ms=<span style="color: #B452CD">12</span>, label=<span style="color: #CD5555">'data'</span>)
|
||||
p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label=<span style="color: #CD5555">'linear'</span>)
|
||||
p3=plt.plot(x_plot,clf3.predict(X3), label=<span style="color: #CD5555">'3rd order'</span>)
|
||||
p10=plt.plot(x_plot,clf10.predict(X10), label=<span style="color: #CD5555">'10th order'</span>)
|
||||
|
||||
|
||||
plt.legend(loc=<span style="color: #B452CD">2</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'$y$'</span>)
|
||||
plt.legend(loc=<span style="color: #CD5555">'best'</span>)
|
||||
plt.title(Title+<span style="color: #CD5555">" (pred.)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
<span style="color: #228B22">#Linear Filename</span>
|
||||
<span style="color: #228B22">#filename_test=Title+"pred-linear.pdf"</span>
|
||||
<span style="color: #228B22">#Tenth Order Filename</span>
|
||||
<span style="color: #228B22">#filename_test=Title+"pred-o10.pdf"</span>
|
||||
<span style="color: #228B22">#plt.savefig(filename_test)</span>
|
||||
<span style="color: #228B22">#plt.ylim((-6,12))</span>
|
||||
</pre></div>
|
||||
The LOOCV prediction performance can be
|
||||
expressed analytically in terms of the known quantities derived from
|
||||
the design matrix and the parameters \( \beta \).
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec43">Lasso regression </h2>
|
||||
</section>
|
||||
<h2 id="___sec52">Bootstrap </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Bootstrapping is a nonparametric approach to statistical inference
|
||||
that substitutes computation for more traditional distributional
|
||||
assumptions and asymptotic results. Bootstrapping offers a number of
|
||||
advantages:
|
||||
|
||||
<ol>
|
||||
<p><li> The bootstrap is quite general, although there are some cases in which it fails.</li>
|
||||
|
||||
<section>
|
||||
<h2 id="___sec44">Logistic regression </h2>
|
||||
<p><li> 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.</li>
|
||||
|
||||
<p><li> It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.</li>
|
||||
<p><li> It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).</li>
|
||||
</ol>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -130,31 +130,51 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -196,7 +216,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2018</h4></center> <!-- date -->
|
||||
<center><h4>Sep 7, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -1236,7 +1256,275 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec35">Code examples for Ridge and Lasso Regression </h2>
|
||||
<h2 id="___sec35">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\label{_auto1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">An example code without the model assessment part </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">sk</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mpl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
<span style="color: #228B22"># The Training Data</span>
|
||||
|
||||
N_train=<span style="color: #B452CD">100</span>
|
||||
|
||||
sigma_train=<span style="color: #B452CD">1</span>;
|
||||
|
||||
<span style="color: #228B22"># Train on integers</span>
|
||||
x=np.linspace(<span style="color: #B452CD">0.05</span>,<span style="color: #B452CD">0.95</span>,N_train)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s = sigma_train*np.random.randn(N_train)
|
||||
|
||||
<span style="color: #228B22">#linear</span>
|
||||
y=<span style="color: #B452CD">2</span>*x+s
|
||||
|
||||
<span style="color: #228B22">#Tenth Order</span>
|
||||
<span style="color: #228B22">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1=plt.plot(x,y, <span style="color: #CD5555">"o"</span>,ms=<span style="color: #B452CD">15</span>, label=<span style="color: #CD5555">'Training'</span>)
|
||||
|
||||
<span style="color: #228B22">#Linear Regression</span>
|
||||
<span style="color: #228B22"># Create linear regression object</span>
|
||||
clf = linear_model.LinearRegression()
|
||||
|
||||
<span style="color: #228B22"># Train the model using the training sets</span>
|
||||
clf.fit(x[:, np.newaxis], y)
|
||||
<span style="color: #228B22"># The coefficients</span>
|
||||
|
||||
xplot=np.linspace(<span style="color: #B452CD">0.02</span>,<span style="color: #B452CD">0.98</span>,<span style="color: #B452CD">200</span>)
|
||||
linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label=<span style="color: #CD5555">'Linear'</span>)
|
||||
|
||||
<span style="color: #228B22">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 = PolynomialFeatures(degree=<span style="color: #B452CD">3</span>)
|
||||
X = poly3.fit_transform(x[:,np.newaxis])
|
||||
clf3 = linear_model.LinearRegression()
|
||||
clf3.fit(X,y)
|
||||
|
||||
|
||||
Xplot=poly3.fit_transform(xplot[:,np.newaxis])
|
||||
poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label=<span style="color: #CD5555">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #228B22">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #228B22">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #228B22">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #228B22">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 = PolynomialFeatures(degree=<span style="color: #B452CD">10</span>)
|
||||
X = poly10.fit_transform(x[:,np.newaxis])
|
||||
clf10 = linear_model.LinearRegression()
|
||||
clf10.fit(X,y)
|
||||
|
||||
Xplot=poly10.fit_transform(xplot[:,np.newaxis])
|
||||
poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label=<span style="color: #CD5555">'Poly 10'</span>)
|
||||
|
||||
axes = plt.gca()
|
||||
axes.set_ylim([-<span style="color: #B452CD">7</span>,<span style="color: #B452CD">7</span>])
|
||||
|
||||
handles, labels=axes.get_legend_handles_labels()
|
||||
plt.legend(handles,labels, loc=<span style="color: #CD5555">'lower center'</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">"$x$"</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">"$y$"</span>)
|
||||
Title=<span style="color: #CD5555">"$N=$"</span>+<span style="color: #658b00">str</span>(N_train)+<span style="color: #CD5555">", $\sigma=$"</span>+<span style="color: #658b00">str</span>(sigma_train)
|
||||
plt.title(Title+<span style="color: #CD5555">" (train)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec40">Generating test data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #228B22">#Number of test data</span>
|
||||
N_test=<span style="color: #B452CD">20</span>
|
||||
|
||||
sigma_test=sigma_train
|
||||
|
||||
max_x=<span style="color: #B452CD">1.2</span>
|
||||
x_test=max_x*np.random.random(N_test)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s_test = sigma_test*np.random.randn(N_test)
|
||||
|
||||
<span style="color: #228B22">#Linear</span>
|
||||
y_test=<span style="color: #B452CD">2</span>*x_test+s_test
|
||||
<span style="color: #228B22">#Tenth order</span>
|
||||
<span style="color: #228B22">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #228B22">#Make design matrices for prediction</span>
|
||||
x_plot=np.linspace(<span style="color: #B452CD">0</span>,max_x, <span style="color: #B452CD">200</span>)
|
||||
X3 = poly3.fit_transform(x_plot[:,np.newaxis])
|
||||
X10 = poly10.fit_transform(x_plot[:,np.newaxis])
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
fig = plt.figure()
|
||||
p1=plt.plot(x_test,y_test.transpose(), <span style="color: #CD5555">'o'</span>, ms=<span style="color: #B452CD">12</span>, label=<span style="color: #CD5555">'data'</span>)
|
||||
p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label=<span style="color: #CD5555">'linear'</span>)
|
||||
p3=plt.plot(x_plot,clf3.predict(X3), label=<span style="color: #CD5555">'3rd order'</span>)
|
||||
p10=plt.plot(x_plot,clf10.predict(X10), label=<span style="color: #CD5555">'10th order'</span>)
|
||||
|
||||
|
||||
plt.legend(loc=<span style="color: #B452CD">2</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'$y$'</span>)
|
||||
plt.legend(loc=<span style="color: #CD5555">'best'</span>)
|
||||
plt.title(Title+<span style="color: #CD5555">" (pred.)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">How can we effectively evaluate the various models? </h2>
|
||||
|
||||
<p>
|
||||
In Ridge regression and the subsequent discussion of its properties
|
||||
the bias or penalty parameter is considered known or `given'. In
|
||||
practice, it is unknown and the user needs to make an informed
|
||||
decision on its value. How do we do that? Much of the same considerations apply to the Lasso method.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec42">Code examples for Ridge and Lasso Regression </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1317,86 +1605,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\label{_auto1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<h2 id="___sec43">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1510,197 +1719,227 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<h2 id="___sec44">Resampling methods </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
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.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec40">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<h2 id="___sec45">Resampling approaches can be computationally expensive </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
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.
|
||||
</div>
|
||||
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">The code </h2>
|
||||
<h2 id="___sec46">Log-likelihood </h2>
|
||||
|
||||
<p>
|
||||
A popular strategy is to choose a penalty parameter that yields a good
|
||||
but parsimonious model. Information criteria measure the balance
|
||||
between model fit and model complexity. One possibility is Aikaike's
|
||||
information criterion (AIC).
|
||||
The AIC measures model fit by the log-likelihood
|
||||
and model complexity is measured by the number of parameters used by
|
||||
the model. The number of model parameters in regular regression simply
|
||||
corresponds to the number of covariates in the model. Or, by the
|
||||
degrees of freedom consumed by the model, which is equivalent to the
|
||||
trace of the hat matrix. For ridge regression it thus seems natural to
|
||||
define model complexity analogously by the trace of the ridge hat
|
||||
matrix. This yields the AIC for the linear regression model with ridge
|
||||
estimates:
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">sk</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn</span> <span style="color: #8B008B; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> PolynomialFeatures
|
||||
$$
|
||||
\begin{align*}
|
||||
\mbox{AIC}(\lambda) & = 2 \, p - 2 \log(\hat{L})
|
||||
\\
|
||||
& = 2 \, \mbox{tr} [\mathbf{H}(\lambda)] - 2 \log\{L[\hat{\beta}(\lambda), \hat{\sigma}^2(\lambda)]\}
|
||||
\\
|
||||
& = 2 \, \sum_{j=1}^p \frac{d_{jj}^2}{d_{jj}^2 + \lambda}
|
||||
+ 2 n \, \log[\sqrt{2 \, \pi} \, \hat{\sigma}(\lambda)] + \frac{1}{\hat{\sigma}^2(\lambda)} \sum_{i=1}^n [y_i - \mathbf{X}_{i, \ast} \, \hat{\beta}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mpl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
|
||||
The value of \( \lambda \) which minimizes \( \mbox{AIC}(\lambda) \) corresponds to the `optimal' balance of model complexity and overfitting.
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
<span style="color: #228B22"># The Training Data</span>
|
||||
|
||||
N_train=<span style="color: #B452CD">100</span>
|
||||
|
||||
sigma_train=<span style="color: #B452CD">1</span>;
|
||||
|
||||
<span style="color: #228B22"># Train on integers</span>
|
||||
x=np.linspace(<span style="color: #B452CD">0.05</span>,<span style="color: #B452CD">0.95</span>,N_train)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s = sigma_train*np.random.randn(N_train)
|
||||
|
||||
<span style="color: #228B22">#linear</span>
|
||||
y=<span style="color: #B452CD">2</span>*x+s
|
||||
|
||||
<span style="color: #228B22">#Tenth Order</span>
|
||||
<span style="color: #228B22">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1=plt.plot(x,y, <span style="color: #CD5555">"o"</span>,ms=<span style="color: #B452CD">15</span>, label=<span style="color: #CD5555">'Training'</span>)
|
||||
|
||||
<span style="color: #228B22">#Linear Regression</span>
|
||||
<span style="color: #228B22"># Create linear regression object</span>
|
||||
clf = linear_model.LinearRegression()
|
||||
|
||||
<span style="color: #228B22"># Train the model using the training sets</span>
|
||||
clf.fit(x[:, np.newaxis], y)
|
||||
<span style="color: #228B22"># The coefficients</span>
|
||||
|
||||
xplot=np.linspace(<span style="color: #B452CD">0.02</span>,<span style="color: #B452CD">0.98</span>,<span style="color: #B452CD">200</span>)
|
||||
linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label=<span style="color: #CD5555">'Linear'</span>)
|
||||
|
||||
<span style="color: #228B22">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 = PolynomialFeatures(degree=<span style="color: #B452CD">3</span>)
|
||||
X = poly3.fit_transform(x[:,np.newaxis])
|
||||
clf3 = linear_model.LinearRegression()
|
||||
clf3.fit(X,y)
|
||||
|
||||
|
||||
Xplot=poly3.fit_transform(xplot[:,np.newaxis])
|
||||
poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label=<span style="color: #CD5555">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #228B22">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #228B22">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #228B22">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #228B22">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #228B22">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 = PolynomialFeatures(degree=<span style="color: #B452CD">10</span>)
|
||||
X = poly10.fit_transform(x[:,np.newaxis])
|
||||
clf10 = linear_model.LinearRegression()
|
||||
clf10.fit(X,y)
|
||||
|
||||
Xplot=poly10.fit_transform(xplot[:,np.newaxis])
|
||||
poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label=<span style="color: #CD5555">'Poly 10'</span>)
|
||||
|
||||
axes = plt.gca()
|
||||
axes.set_ylim([-<span style="color: #B452CD">7</span>,<span style="color: #B452CD">7</span>])
|
||||
|
||||
handles, labels=axes.get_legend_handles_labels()
|
||||
plt.legend(handles,labels, loc=<span style="color: #CD5555">'lower center'</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">"$x$"</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">"$y$"</span>)
|
||||
Title=<span style="color: #CD5555">"$N=$"</span>+<span style="color: #658b00">str</span>(N_train)+<span style="color: #CD5555">", $\sigma=$"</span>+<span style="color: #658b00">str</span>(sigma_train)
|
||||
plt.title(Title+<span style="color: #CD5555">" (train)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec42">Generating test data </h2>
|
||||
<h2 id="___sec47">Cross-validation </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #228B22">#Number of test data</span>
|
||||
N_test=<span style="color: #B452CD">20</span>
|
||||
|
||||
sigma_test=sigma_train
|
||||
|
||||
max_x=<span style="color: #B452CD">1.2</span>
|
||||
x_test=max_x*np.random.random(N_test)
|
||||
<span style="color: #228B22"># Draw random noise</span>
|
||||
s_test = sigma_test*np.random.randn(N_test)
|
||||
|
||||
<span style="color: #228B22">#Linear</span>
|
||||
y_test=<span style="color: #B452CD">2</span>*x_test+s_test
|
||||
<span style="color: #228B22">#Tenth order</span>
|
||||
<span style="color: #228B22">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #228B22">#Make design matrices for prediction</span>
|
||||
x_plot=np.linspace(<span style="color: #B452CD">0</span>,max_x, <span style="color: #B452CD">200</span>)
|
||||
X3 = poly3.fit_transform(x_plot[:,np.newaxis])
|
||||
X10 = poly10.fit_transform(x_plot[:,np.newaxis])
|
||||
|
||||
%matplotlib notebook
|
||||
|
||||
fig = plt.figure()
|
||||
p1=plt.plot(x_test,y_test.transpose(), <span style="color: #CD5555">'o'</span>, ms=<span style="color: #B452CD">12</span>, label=<span style="color: #CD5555">'data'</span>)
|
||||
p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label=<span style="color: #CD5555">'linear'</span>)
|
||||
p3=plt.plot(x_plot,clf3.predict(X3), label=<span style="color: #CD5555">'3rd order'</span>)
|
||||
p10=plt.plot(x_plot,clf10.predict(X10), label=<span style="color: #CD5555">'10th order'</span>)
|
||||
|
||||
|
||||
plt.legend(loc=<span style="color: #B452CD">2</span>)
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'$y$'</span>)
|
||||
plt.legend(loc=<span style="color: #CD5555">'best'</span>)
|
||||
plt.title(Title+<span style="color: #CD5555">" (pred.)"</span>)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
<span style="color: #228B22">#Linear Filename</span>
|
||||
<span style="color: #228B22">#filename_test=Title+"pred-linear.pdf"</span>
|
||||
<span style="color: #228B22">#Tenth Order Filename</span>
|
||||
<span style="color: #228B22">#filename_test=Title+"pred-o10.pdf"</span>
|
||||
<span style="color: #228B22">#plt.savefig(filename_test)</span>
|
||||
<span style="color: #228B22">#plt.ylim((-6,12))</span>
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec43">Lasso regression </h2>
|
||||
Instead of choosing the penalty parameter to balance model fit with
|
||||
model complexity, cross-validation requires it (i.e. the penalty
|
||||
parameter) to yield a model with good prediction
|
||||
performance. Commonly, this performance is evaluated on novel
|
||||
data. Novel data need not be easy to come by and one has to make do
|
||||
with the data at hand. The setting of `original' and novel data is
|
||||
then mimicked by sample splitting: the data set is divided into two
|
||||
(groups of samples). One of these two data sets, called the <em>training
|
||||
set</em>, plays the role of `original' data on which the model is
|
||||
built. The second of these data sets, called the <em>test set</em>, plays the
|
||||
role of the `novel' data and is used to evaluate the prediction
|
||||
performance (often operationalized as the log-likelihood or the
|
||||
prediction error or its square or the R2 score) of the model built on the training data set. This
|
||||
procedure (model building and prediction evaluation on training and
|
||||
test set, respectively) is done for a collection of possible penalty
|
||||
parameter choices. The penalty parameter that yields the model with
|
||||
the best prediction performance is to be preferred. The thus obtained
|
||||
performance evaluation depends on the actual split of the data set. To
|
||||
remove this dependence the data set is split many times into a
|
||||
training and test set. For each split the model parameters are
|
||||
estimated for all choices of \( \lambda \) using the training data and
|
||||
estimated parameters are evaluated on the corresponding test set. The
|
||||
penalty parameter that on average over the test sets performs best (in
|
||||
some sense) is then selected.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec44">Logistic regression </h2>
|
||||
<h2 id="___sec48">Computationally expensive </h2>
|
||||
|
||||
<p>
|
||||
The validation set approach is conceptually simple and is easy to implement. But it has two potential drawbacks:
|
||||
|
||||
<ul>
|
||||
<li> The validation estimate of the test error rate can be highly variable, depending on precisely which observations are included in the training set and which observations are included in the validation set.</li>
|
||||
<li> In the validation approach, only a subset of the observations, those that are included in the training set rather than in the validation set are used to fit the model. Since statistical methods tend to perform worse when trained on fewer observations, this suggests that the validation set error rate may tend to overestimate the test error rate for the model fit on the entire data set.</li>
|
||||
</ul>
|
||||
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec49">Various steps in cross-validation </h2>
|
||||
|
||||
<p>
|
||||
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).
|
||||
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec50">How to set up the cross-validation for Ridge and/or Lasso </h2>
|
||||
|
||||
<ol>
|
||||
<li> Define a range of interest for the penalty parameter.</li>
|
||||
<li> Divide the data set into training and test set comprising samples \( \{1, \ldots, n\} \setminus i \) and \( \{ i \} \), respectively.</li>
|
||||
<li> Fit the linear regression model by means of ridge estimation for each \( \lambda \) in the grid using the training set as</li>
|
||||
</ol>
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{\beta}_{-i}(\lambda) & = ( \hat{X}_{-i, \ast}^{\top}
|
||||
\hat{X}_{-i, \ast} + \lambda \hat{I}_{pp})^{-1}
|
||||
\hat{X}_{-i, \ast}^{\top} \hat{y}_{-i}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
and the corresponding estimate of the error variance \( \hat{\sigma}_{-i}^2(\lambda) \).
|
||||
|
||||
<ol>
|
||||
<li> Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \hat{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.</li>
|
||||
<li> Repeat steps 1) to 3) such that each sample plays the role of the test set once.</li>
|
||||
<li> Average the prediction performances of the test sets at each grid point of the penalty bias/parameter</li>
|
||||
</ol>
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{1}{n} \sum_{i = 1}^n \log\{L[Y_i, \mathbf{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\}.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
The quantity above is called the <em>cross-validated log-likelihood</em>. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data.
|
||||
|
||||
<ol>
|
||||
<li> The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.</li>
|
||||
</ol>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec51">Predicted Residual Error Sum of Squares </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Another approach in the LOOCV scheme is to the use the so-called Predicted Residual Error Sum of Squares (PRESS).
|
||||
|
||||
<p>
|
||||
We can define the optimal penalty parameter to minimize
|
||||
$$
|
||||
\begin{align*}
|
||||
\lambda_{\mbox{{\tiny opt}}} = \arg \min_{\lambda} \frac{1}{n} \sum_{i=1}^n [y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The LOOCV prediction performance can be
|
||||
expressed analytically in terms of the known quantities derived from
|
||||
the design matrix and the parameters \( \beta \).
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec52">Bootstrap </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Bootstrapping is a nonparametric approach to statistical inference
|
||||
that substitutes computation for more traditional distributional
|
||||
assumptions and asymptotic results. Bootstrapping offers a number of
|
||||
advantages:
|
||||
|
||||
<ol>
|
||||
<li> The bootstrap is quite general, although there are some cases in which it fails.</li>
|
||||
<li> 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.</li>
|
||||
<li> It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.</li>
|
||||
<li> It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -135,31 +135,51 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
'___sec32'),
|
||||
('Expectation value and variance', 2, None, '___sec33'),
|
||||
('The singular value decompostion', 2, None, '___sec34'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('From standard regression to Ridge regressions',
|
||||
2,
|
||||
None,
|
||||
'___sec36'),
|
||||
('Fixing the singularity', 2, None, '___sec37'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec38'),
|
||||
'___sec35'),
|
||||
('Fixing the singularity', 2, None, '___sec36'),
|
||||
('Fitting vs. predicting when data is in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
'___sec37'),
|
||||
('Fitting versus predicting when data is not in the model class',
|
||||
2,
|
||||
None,
|
||||
'___sec40'),
|
||||
('The code', 2, None, '___sec41'),
|
||||
('Generating test data', 2, None, '___sec42'),
|
||||
('Lasso regression', 2, None, '___sec43'),
|
||||
('Logistic regression', 2, None, '___sec44')]}
|
||||
'___sec38'),
|
||||
('An example code without the model assessment part',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Generating test data', 2, None, '___sec40'),
|
||||
('How can we effectively evaluate the various models?',
|
||||
2,
|
||||
None,
|
||||
'___sec41'),
|
||||
('Code examples for Ridge and Lasso Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec42'),
|
||||
('A second-order polynomial with Ridge and Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec43'),
|
||||
('Resampling methods', 2, None, '___sec44'),
|
||||
('Resampling approaches can be computationally expensive',
|
||||
2,
|
||||
None,
|
||||
'___sec45'),
|
||||
('Log-likelihood', 2, None, '___sec46'),
|
||||
('Cross-validation', 2, None, '___sec47'),
|
||||
('Computationally expensive', 2, None, '___sec48'),
|
||||
('Various steps in cross-validation', 2, None, '___sec49'),
|
||||
('How to set up the cross-validation for Ridge and/or Lasso',
|
||||
2,
|
||||
None,
|
||||
'___sec50'),
|
||||
('Predicted Residual Error Sum of Squares', 2, None, '___sec51'),
|
||||
('Bootstrap', 2, None, '___sec52')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -201,7 +221,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2018</h4></center> <!-- date -->
|
||||
<center><h4>Sep 7, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -1241,7 +1261,275 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec35">Code examples for Ridge and Lasso Regression </h2>
|
||||
<h2 id="___sec35">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\label{_auto1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">An example code without the model assessment part </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sk</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mpl</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
<span style="color: #408080; font-style: italic"># The Training Data</span>
|
||||
|
||||
N_train<span style="color: #666666">=100</span>
|
||||
|
||||
sigma_train<span style="color: #666666">=1</span>;
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train on integers</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.05</span>,<span style="color: #666666">0.95</span>,N_train)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s <span style="color: #666666">=</span> sigma_train<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_train)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#linear</span>
|
||||
y<span style="color: #666666">=2*</span>x<span style="color: #666666">+</span>s
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order</span>
|
||||
<span style="color: #408080; font-style: italic">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x,y, <span style="color: #BA2121">"o"</span>,ms<span style="color: #666666">=15</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'Training'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Regression</span>
|
||||
<span style="color: #408080; font-style: italic"># Create linear regression object</span>
|
||||
clf <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train the model using the training sets</span>
|
||||
clf<span style="color: #666666">.</span>fit(x[:, np<span style="color: #666666">.</span>newaxis], y)
|
||||
<span style="color: #408080; font-style: italic"># The coefficients</span>
|
||||
|
||||
xplot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.02</span>,<span style="color: #666666">0.98</span>,<span style="color: #666666">200</span>)
|
||||
linear_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf<span style="color: #666666">.</span>predict(xplot[:, np<span style="color: #666666">.</span>newaxis]),label<span style="color: #666666">=</span><span style="color: #BA2121">'Linear'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=3</span>)
|
||||
X <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf3 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf3<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly3<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly3_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf3<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #408080; font-style: italic">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=10</span>)
|
||||
X <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf10 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf10<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly10<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly10_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf10<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 10'</span>)
|
||||
|
||||
axes <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>gca()
|
||||
axes<span style="color: #666666">.</span>set_ylim([<span style="color: #666666">-7</span>,<span style="color: #666666">7</span>])
|
||||
|
||||
handles, labels<span style="color: #666666">=</span>axes<span style="color: #666666">.</span>get_legend_handles_labels()
|
||||
plt<span style="color: #666666">.</span>legend(handles,labels, loc<span style="color: #666666">=</span><span style="color: #BA2121">'lower center'</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x$"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>)
|
||||
Title<span style="color: #666666">=</span><span style="color: #BA2121">"$N=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(N_train)<span style="color: #666666">+</span><span style="color: #BA2121">", $\sigma=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(sigma_train)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (train)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec40">Generating test data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Number of test data</span>
|
||||
N_test<span style="color: #666666">=20</span>
|
||||
|
||||
sigma_test<span style="color: #666666">=</span>sigma_train
|
||||
|
||||
max_x<span style="color: #666666">=1.2</span>
|
||||
x_test<span style="color: #666666">=</span>max_x<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>random(N_test)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s_test <span style="color: #666666">=</span> sigma_test<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear</span>
|
||||
y_test<span style="color: #666666">=2*</span>x_test<span style="color: #666666">+</span>s_test
|
||||
<span style="color: #408080; font-style: italic">#Tenth order</span>
|
||||
<span style="color: #408080; font-style: italic">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Make design matrices for prediction</span>
|
||||
x_plot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>,max_x, <span style="color: #666666">200</span>)
|
||||
X3 <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
X10 <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure()
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_test,y_test<span style="color: #666666">.</span>transpose(), <span style="color: #BA2121">'o'</span>, ms<span style="color: #666666">=12</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'data'</span>)
|
||||
p2<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf<span style="color: #666666">.</span>predict(x_plot[:,np<span style="color: #666666">.</span>newaxis]), label<span style="color: #666666">=</span><span style="color: #BA2121">'linear'</span>)
|
||||
p3<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf3<span style="color: #666666">.</span>predict(X3), label<span style="color: #666666">=</span><span style="color: #BA2121">'3rd order'</span>)
|
||||
p10<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf10<span style="color: #666666">.</span>predict(X10), label<span style="color: #666666">=</span><span style="color: #BA2121">'10th order'</span>)
|
||||
|
||||
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">'best'</span>)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (pred.)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">How can we effectively evaluate the various models? </h2>
|
||||
|
||||
<p>
|
||||
In Ridge regression and the subsequent discussion of its properties
|
||||
the bias or penalty parameter is considered known or `given'. In
|
||||
practice, it is unknown and the user needs to make an informed
|
||||
decision on its value. How do we do that? Much of the same considerations apply to the Lasso method.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec42">Code examples for Ridge and Lasso Regression </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1322,86 +1610,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">From standard regression to Ridge regressions </h2>
|
||||
|
||||
<p>
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix \( \hat{X} \) (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of \( \hat{X} \)
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
$$
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The columns of \( \hat{X} \) are linearly dependent. We se this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of \( \mathbf{X} \) is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
<p>
|
||||
Super-collinearity of an \( (n \times p) \)-dimensional design matrix \( \mathbf{X} \) implies
|
||||
that the inverse of the matrix \( \hat{X}^T\hat{x} \) (the matrix we needto invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
We see easily that \( \mbox{det}(\hat{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0 \). Hence, \( \mathbf{X} \) is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix \( \hat{X} \) has at least an eigenvalue which is zero.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Fixing the singularity </h2>
|
||||
|
||||
<p>
|
||||
If our design matrix \( \hat{X} \) which enters the linear regression problem
|
||||
$$
|
||||
\begin{align}
|
||||
\hat{\beta} & = (\hat{X}^{T} \hat{X})^{-1} \hat{X}^{T} \hat{y},
|
||||
\label{_auto1}
|
||||
\end{align}
|
||||
$$
|
||||
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of \( \hat{X}^T\hat{X} \) and we cannot find the parameters (estimators) \( \beta_i \).
|
||||
The estimators are only well-defined if \( (\hat{X}^{T}\hat{X})^{-1} \) exits.
|
||||
This is more likely to happen when the matrix \( \hat{X} \) is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters \( \beta_i \) cannot be estimated.
|
||||
|
||||
<p>
|
||||
The <em>ad hoc</em> approach which was introduced in the 70s was simply to add a diagonal component to the matrix to invert, that is we change
|
||||
$$
|
||||
\hat{X}^{T} \hat{X} \rightarrow \hat{X}^{T} \hat{X}+\lambda \hat{I},
|
||||
$$
|
||||
|
||||
where \( \hat{I} \) is the identity matrix.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<h2 id="___sec43">A second-order polynomial with Ridge and Lasso </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1515,197 +1724,227 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">Fitting vs. predicting when data is in the model class </h2>
|
||||
|
||||
<h2 id="___sec44">Resampling methods </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
We start by considering the case
|
||||
\( f(x)=2x \).
|
||||
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.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Then the data is clearly generated by a model that is contained within
|
||||
all three model classes we are using to make predictions (linear
|
||||
models, third order polynomials, and tenth order polynomials).
|
||||
|
||||
<p>
|
||||
Run the code for the following cases:
|
||||
|
||||
<ol>
|
||||
<li> For \( f(x)=2x \) , \( Ntrain=10 \) and \( \sigma =0 \) (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when \( x \in [0,1] \) . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?</li>
|
||||
<li> Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?</li>
|
||||
<li> Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example \( x \in [0,1.2] \) ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?</li>
|
||||
<li> Repeat the above for \( f(x)=2x \) , \( Ntrain=10 \) , and \( \sigma=1 \) . What changes?</li>
|
||||
</ol>
|
||||
|
||||
Repeat the exercises above for \( f(x)=2x \) , \( Ntrain=100 \) , and \( \sigma=1 \) . What changes?
|
||||
Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec40">Fitting versus predicting when data is not in the model class </h2>
|
||||
|
||||
<h2 id="___sec45">Resampling approaches can be computationally expensive </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider \( f(x)=2x-10x^5+15x^{10} \) . Notice that the for linear and third-order polynomial the true model \( f(x) \) is not contained in model class.
|
||||
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.
|
||||
</div>
|
||||
|
||||
<ol>
|
||||
<li> Do better fits lead to better predictions?</li>
|
||||
<li> What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points \( Ntrain \) and \( \sigma \)?</li>
|
||||
</ol>
|
||||
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">The code </h2>
|
||||
<h2 id="___sec46">Log-likelihood </h2>
|
||||
|
||||
<p>
|
||||
A popular strategy is to choose a penalty parameter that yields a good
|
||||
but parsimonious model. Information criteria measure the balance
|
||||
between model fit and model complexity. One possibility is Aikaike's
|
||||
information criterion (AIC).
|
||||
The AIC measures model fit by the log-likelihood
|
||||
and model complexity is measured by the number of parameters used by
|
||||
the model. The number of model parameters in regular regression simply
|
||||
corresponds to the number of covariates in the model. Or, by the
|
||||
degrees of freedom consumed by the model, which is equivalent to the
|
||||
trace of the hat matrix. For ridge regression it thus seems natural to
|
||||
define model complexity analogously by the trace of the ridge hat
|
||||
matrix. This yields the AIC for the linear regression model with ridge
|
||||
estimates:
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sk</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn</span> <span style="color: #008000; font-weight: bold">import</span> datasets, linear_model
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
$$
|
||||
\begin{align*}
|
||||
\mbox{AIC}(\lambda) & = 2 \, p - 2 \log(\hat{L})
|
||||
\\
|
||||
& = 2 \, \mbox{tr} [\mathbf{H}(\lambda)] - 2 \log\{L[\hat{\beta}(\lambda), \hat{\sigma}^2(\lambda)]\}
|
||||
\\
|
||||
& = 2 \, \sum_{j=1}^p \frac{d_{jj}^2}{d_{jj}^2 + \lambda}
|
||||
+ 2 n \, \log[\sqrt{2 \, \pi} \, \hat{\sigma}(\lambda)] + \frac{1}{\hat{\sigma}^2(\lambda)} \sum_{i=1}^n [y_i - \mathbf{X}_{i, \ast} \, \hat{\beta}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mpl</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
|
||||
The value of \( \lambda \) which minimizes \( \mbox{AIC}(\lambda) \) corresponds to the `optimal' balance of model complexity and overfitting.
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
<span style="color: #408080; font-style: italic"># The Training Data</span>
|
||||
|
||||
N_train<span style="color: #666666">=100</span>
|
||||
|
||||
sigma_train<span style="color: #666666">=1</span>;
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train on integers</span>
|
||||
x<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.05</span>,<span style="color: #666666">0.95</span>,N_train)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s <span style="color: #666666">=</span> sigma_train<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_train)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#linear</span>
|
||||
y<span style="color: #666666">=2*</span>x<span style="color: #666666">+</span>s
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order</span>
|
||||
<span style="color: #408080; font-style: italic">#y=2*x-10*x**5+15*x**10+s</span>
|
||||
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x,y, <span style="color: #BA2121">"o"</span>,ms<span style="color: #666666">=15</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'Training'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Regression</span>
|
||||
<span style="color: #408080; font-style: italic"># Create linear regression object</span>
|
||||
clf <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Train the model using the training sets</span>
|
||||
clf<span style="color: #666666">.</span>fit(x[:, np<span style="color: #666666">.</span>newaxis], y)
|
||||
<span style="color: #408080; font-style: italic"># The coefficients</span>
|
||||
|
||||
xplot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0.02</span>,<span style="color: #666666">0.98</span>,<span style="color: #666666">200</span>)
|
||||
linear_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf<span style="color: #666666">.</span>predict(xplot[:, np<span style="color: #666666">.</span>newaxis]),label<span style="color: #666666">=</span><span style="color: #BA2121">'Linear'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Polynomial Regression</span>
|
||||
|
||||
|
||||
poly3 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=3</span>)
|
||||
X <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf3 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf3<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly3<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly3_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf3<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 3'</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#poly5 = PolynomialFeatures(degree=5)</span>
|
||||
<span style="color: #408080; font-style: italic">#X = poly5.fit_transform(x[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5 = linear_model.LinearRegression()</span>
|
||||
<span style="color: #408080; font-style: italic">#clf5.fit(X,y)</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Xplot=poly5.fit_transform(xplot[:,np.newaxis])</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)</span>
|
||||
|
||||
poly10 <span style="color: #666666">=</span> PolynomialFeatures(degree<span style="color: #666666">=10</span>)
|
||||
X <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x[:,np<span style="color: #666666">.</span>newaxis])
|
||||
clf10 <span style="color: #666666">=</span> linear_model<span style="color: #666666">.</span>LinearRegression()
|
||||
clf10<span style="color: #666666">.</span>fit(X,y)
|
||||
|
||||
Xplot<span style="color: #666666">=</span>poly10<span style="color: #666666">.</span>fit_transform(xplot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
poly10_plot<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(xplot, clf10<span style="color: #666666">.</span>predict(Xplot), label<span style="color: #666666">=</span><span style="color: #BA2121">'Poly 10'</span>)
|
||||
|
||||
axes <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>gca()
|
||||
axes<span style="color: #666666">.</span>set_ylim([<span style="color: #666666">-7</span>,<span style="color: #666666">7</span>])
|
||||
|
||||
handles, labels<span style="color: #666666">=</span>axes<span style="color: #666666">.</span>get_legend_handles_labels()
|
||||
plt<span style="color: #666666">.</span>legend(handles,labels, loc<span style="color: #666666">=</span><span style="color: #BA2121">'lower center'</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x$"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>)
|
||||
Title<span style="color: #666666">=</span><span style="color: #BA2121">"$N=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(N_train)<span style="color: #666666">+</span><span style="color: #BA2121">", $\sigma=$"</span><span style="color: #666666">+</span><span style="color: #008000">str</span>(sigma_train)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (train)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec42">Generating test data </h2>
|
||||
<h2 id="___sec47">Cross-validation </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Generate Test Data</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Number of test data</span>
|
||||
N_test<span style="color: #666666">=20</span>
|
||||
|
||||
sigma_test<span style="color: #666666">=</span>sigma_train
|
||||
|
||||
max_x<span style="color: #666666">=1.2</span>
|
||||
x_test<span style="color: #666666">=</span>max_x<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>random(N_test)
|
||||
<span style="color: #408080; font-style: italic"># Draw random noise</span>
|
||||
s_test <span style="color: #666666">=</span> sigma_test<span style="color: #666666">*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(N_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear</span>
|
||||
y_test<span style="color: #666666">=2*</span>x_test<span style="color: #666666">+</span>s_test
|
||||
<span style="color: #408080; font-style: italic">#Tenth order</span>
|
||||
<span style="color: #408080; font-style: italic">#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Make design matrices for prediction</span>
|
||||
x_plot<span style="color: #666666">=</span>np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>,max_x, <span style="color: #666666">200</span>)
|
||||
X3 <span style="color: #666666">=</span> poly3<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
X10 <span style="color: #666666">=</span> poly10<span style="color: #666666">.</span>fit_transform(x_plot[:,np<span style="color: #666666">.</span>newaxis])
|
||||
|
||||
<span style="color: #666666">%</span>matplotlib notebook
|
||||
|
||||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure()
|
||||
p1<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_test,y_test<span style="color: #666666">.</span>transpose(), <span style="color: #BA2121">'o'</span>, ms<span style="color: #666666">=12</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">'data'</span>)
|
||||
p2<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf<span style="color: #666666">.</span>predict(x_plot[:,np<span style="color: #666666">.</span>newaxis]), label<span style="color: #666666">=</span><span style="color: #BA2121">'linear'</span>)
|
||||
p3<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf3<span style="color: #666666">.</span>predict(X3), label<span style="color: #666666">=</span><span style="color: #BA2121">'3rd order'</span>)
|
||||
p10<span style="color: #666666">=</span>plt<span style="color: #666666">.</span>plot(x_plot,clf10<span style="color: #666666">.</span>predict(X10), label<span style="color: #666666">=</span><span style="color: #BA2121">'10th order'</span>)
|
||||
|
||||
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">'best'</span>)
|
||||
plt<span style="color: #666666">.</span>title(Title<span style="color: #666666">+</span><span style="color: #BA2121">" (pred.)"</span>)
|
||||
plt<span style="color: #666666">.</span>tight_layout()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Linear Filename</span>
|
||||
<span style="color: #408080; font-style: italic">#filename_test=Title+"pred-linear.pdf"</span>
|
||||
<span style="color: #408080; font-style: italic">#Tenth Order Filename</span>
|
||||
<span style="color: #408080; font-style: italic">#filename_test=Title+"pred-o10.pdf"</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.savefig(filename_test)</span>
|
||||
<span style="color: #408080; font-style: italic">#plt.ylim((-6,12))</span>
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec43">Lasso regression </h2>
|
||||
Instead of choosing the penalty parameter to balance model fit with
|
||||
model complexity, cross-validation requires it (i.e. the penalty
|
||||
parameter) to yield a model with good prediction
|
||||
performance. Commonly, this performance is evaluated on novel
|
||||
data. Novel data need not be easy to come by and one has to make do
|
||||
with the data at hand. The setting of `original' and novel data is
|
||||
then mimicked by sample splitting: the data set is divided into two
|
||||
(groups of samples). One of these two data sets, called the <em>training
|
||||
set</em>, plays the role of `original' data on which the model is
|
||||
built. The second of these data sets, called the <em>test set</em>, plays the
|
||||
role of the `novel' data and is used to evaluate the prediction
|
||||
performance (often operationalized as the log-likelihood or the
|
||||
prediction error or its square or the R2 score) of the model built on the training data set. This
|
||||
procedure (model building and prediction evaluation on training and
|
||||
test set, respectively) is done for a collection of possible penalty
|
||||
parameter choices. The penalty parameter that yields the model with
|
||||
the best prediction performance is to be preferred. The thus obtained
|
||||
performance evaluation depends on the actual split of the data set. To
|
||||
remove this dependence the data set is split many times into a
|
||||
training and test set. For each split the model parameters are
|
||||
estimated for all choices of \( \lambda \) using the training data and
|
||||
estimated parameters are evaluated on the corresponding test set. The
|
||||
penalty parameter that on average over the test sets performs best (in
|
||||
some sense) is then selected.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec44">Logistic regression </h2>
|
||||
<h2 id="___sec48">Computationally expensive </h2>
|
||||
|
||||
<p>
|
||||
The validation set approach is conceptually simple and is easy to implement. But it has two potential drawbacks:
|
||||
|
||||
<ul>
|
||||
<li> The validation estimate of the test error rate can be highly variable, depending on precisely which observations are included in the training set and which observations are included in the validation set.</li>
|
||||
<li> In the validation approach, only a subset of the observations, those that are included in the training set rather than in the validation set are used to fit the model. Since statistical methods tend to perform worse when trained on fewer observations, this suggests that the validation set error rate may tend to overestimate the test error rate for the model fit on the entire data set.</li>
|
||||
</ul>
|
||||
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec49">Various steps in cross-validation </h2>
|
||||
|
||||
<p>
|
||||
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).
|
||||
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec50">How to set up the cross-validation for Ridge and/or Lasso </h2>
|
||||
|
||||
<ol>
|
||||
<li> Define a range of interest for the penalty parameter.</li>
|
||||
<li> Divide the data set into training and test set comprising samples \( \{1, \ldots, n\} \setminus i \) and \( \{ i \} \), respectively.</li>
|
||||
<li> Fit the linear regression model by means of ridge estimation for each \( \lambda \) in the grid using the training set as</li>
|
||||
</ol>
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\hat{\beta}_{-i}(\lambda) & = ( \hat{X}_{-i, \ast}^{\top}
|
||||
\hat{X}_{-i, \ast} + \lambda \hat{I}_{pp})^{-1}
|
||||
\hat{X}_{-i, \ast}^{\top} \hat{y}_{-i}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
and the corresponding estimate of the error variance \( \hat{\sigma}_{-i}^2(\lambda) \).
|
||||
|
||||
<ol>
|
||||
<li> Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \hat{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.</li>
|
||||
<li> Repeat steps 1) to 3) such that each sample plays the role of the test set once.</li>
|
||||
<li> Average the prediction performances of the test sets at each grid point of the penalty bias/parameter</li>
|
||||
</ol>
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{1}{n} \sum_{i = 1}^n \log\{L[Y_i, \mathbf{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\}.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
The quantity above is called the <em>cross-validated log-likelihood</em>. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data.
|
||||
|
||||
<ol>
|
||||
<li> The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.</li>
|
||||
</ol>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec51">Predicted Residual Error Sum of Squares </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Another approach in the LOOCV scheme is to the use the so-called Predicted Residual Error Sum of Squares (PRESS).
|
||||
|
||||
<p>
|
||||
We can define the optimal penalty parameter to minimize
|
||||
$$
|
||||
\begin{align*}
|
||||
\lambda_{\mbox{{\tiny opt}}} = \arg \min_{\lambda} \frac{1}{n} \sum_{i=1}^n [y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)]^2.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
<p>
|
||||
The LOOCV prediction performance can be
|
||||
expressed analytically in terms of the known quantities derived from
|
||||
the design matrix and the parameters \( \beta \).
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec52">Bootstrap </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
Bootstrapping is a nonparametric approach to statistical inference
|
||||
that substitutes computation for more traditional distributional
|
||||
assumptions and asymptotic results. Bootstrapping offers a number of
|
||||
advantages:
|
||||
|
||||
<ol>
|
||||
<li> The bootstrap is quite general, although there are some cases in which it fails.</li>
|
||||
<li> 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.</li>
|
||||
<li> It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.</li>
|
||||
<li> It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Sep 6, 2018**\n",
|
||||
"Date: **Sep 7, 2018**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -1606,95 +1606,6 @@
|
||||
"$$"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Code examples for Ridge and Lasso Regression"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np\n",
|
||||
"from sklearn import linear_model\n",
|
||||
"from sklearn.linear_model import LinearRegression\n",
|
||||
"from sklearn.metrics import mean_squared_error, r2_score\n",
|
||||
"\n",
|
||||
"#creating data with random noise\n",
|
||||
"x=np.arange(50)\n",
|
||||
"\n",
|
||||
"delta=np.random.uniform(-2.5,2.5, size=(50))\n",
|
||||
"np.random.shuffle(delta)\n",
|
||||
"y =0.5*x+5+delta\n",
|
||||
"\n",
|
||||
"#arranging data into 2x50 matrix\n",
|
||||
"a=np.array(x) #inputs\n",
|
||||
"b=np.array(y) #outputs\n",
|
||||
"\n",
|
||||
"#Split into training and test\n",
|
||||
"X_train=a[:37, np.newaxis]\n",
|
||||
"X_test=a[37:, np.newaxis]\n",
|
||||
"y_train=b[:37]\n",
|
||||
"y_test=b[37:]\n",
|
||||
"\n",
|
||||
"print (\"X_train: \", X_train.shape)\n",
|
||||
"print (\"y_train: \", y_train.shape)\n",
|
||||
"print (\"X_test: \", X_test.shape)\n",
|
||||
"print (\"y_test: \", y_test.shape)\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Ordinary Least Squares\")\n",
|
||||
"#Add Ordinary Least Squares fit\n",
|
||||
"reg=LinearRegression()\n",
|
||||
"reg.fit(X_train, y_train)\n",
|
||||
"pred=reg.predict(X_test)\n",
|
||||
"print (\"Prediction Shape: \", pred.shape)\n",
|
||||
"\n",
|
||||
"print('Coefficients: \\n', reg.coef_)\n",
|
||||
"# The mean squared error\n",
|
||||
"print(\"Mean squared error: %.2f\"\n",
|
||||
" % mean_squared_error(y_test, pred))\n",
|
||||
"# Explained variance score: 1 is perfect prediction\n",
|
||||
"print('Variance score: %.2f' % r2_score(y_test, pred))\n",
|
||||
"\n",
|
||||
"#plot\n",
|
||||
"plt.scatter(X_test,y_test,color='green', label=\"Training Data\")\n",
|
||||
"plt.plot(X_test, pred, color='black', label=\"Fit Line\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Ridge Regression\")\n",
|
||||
"\n",
|
||||
"ridge=linear_model.RidgeCV(alphas=[0.1,1.0,10.0])\n",
|
||||
"ridge.fit(X_train,y_train)\n",
|
||||
"print (\"Ridge Coefficient: \",ridge.coef_)\n",
|
||||
"print (\"Ridge Intercept: \", ridge.intercept_)\n",
|
||||
"#Look into graphing with Ridge fit\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Lasso\")\n",
|
||||
"lasso=linear_model.Lasso(alpha=0.1)\n",
|
||||
"lasso.fit(X_train,y_train)\n",
|
||||
"predl=lasso.predict(X_test)\n",
|
||||
"print(\"Lasso Coefficient: \", lasso.coef_)\n",
|
||||
"print(\"Lasso Intercept: \", lasso.intercept_)\n",
|
||||
"plt.scatter(X_test,y_test,color='green', label=\"Training Data\")\n",
|
||||
"plt.plot(X_test, predl, color='blue', label=\"Lasso\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -1816,7 +1727,141 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## A second-order polynomial with Ridge and Lasso"
|
||||
"\n",
|
||||
"\n",
|
||||
"## Fitting vs. predicting when data is in the model class\n",
|
||||
"\n",
|
||||
"We start by considering the case\n",
|
||||
"$f(x)=2x$.\n",
|
||||
"\n",
|
||||
"Then the data is clearly generated by a model that is contained within\n",
|
||||
"all three model classes we are using to make predictions (linear\n",
|
||||
"models, third order polynomials, and tenth order polynomials).\n",
|
||||
"\n",
|
||||
"Run the code for the following cases:\n",
|
||||
"\n",
|
||||
"1. For $f(x)=2x$ , $Ntrain=10$ and $\\sigma =0$ (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when $x \\in [0,1]$ . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?\n",
|
||||
"\n",
|
||||
"2. Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?\n",
|
||||
"\n",
|
||||
"3. Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example $x \\in [0,1.2]$ ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?\n",
|
||||
"\n",
|
||||
"4. Repeat the above for $f(x)=2x$ , $Ntrain=10$ , and $\\sigma=1$ . What changes?\n",
|
||||
"\n",
|
||||
"Repeat the exercises above for $f(x)=2x$ , $Ntrain=100$ , and $\\sigma=1$ . What changes?\n",
|
||||
"Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Fitting versus predicting when data is not in the model class\n",
|
||||
"\n",
|
||||
"Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider $f(x)=2x-10x^5+15x^{10}$ . Notice that the for linear and third-order polynomial the true model $f(x)$ is not contained in model class.\n",
|
||||
"\n",
|
||||
"1. Do better fits lead to better predictions?\n",
|
||||
"\n",
|
||||
"2. What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points $Ntrain$ and $\\sigma$?\n",
|
||||
"\n",
|
||||
"Summarize what you think you learned about the relationship of knowing the true model class and predictive power.\n",
|
||||
"\n",
|
||||
"## An example code without the model assessment part"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import sklearn as sk\n",
|
||||
"from sklearn import datasets, linear_model\n",
|
||||
"from sklearn.preprocessing import PolynomialFeatures\n",
|
||||
"\n",
|
||||
"import matplotlib as mpl\n",
|
||||
"from matplotlib import pyplot as plt\n",
|
||||
"\n",
|
||||
"%matplotlib notebook\n",
|
||||
"\n",
|
||||
"# The Training Data\n",
|
||||
"\n",
|
||||
"N_train=100\n",
|
||||
"\n",
|
||||
"sigma_train=1;\n",
|
||||
"\n",
|
||||
"# Train on integers\n",
|
||||
"x=np.linspace(0.05,0.95,N_train)\n",
|
||||
"# Draw random noise\n",
|
||||
"s = sigma_train*np.random.randn(N_train)\n",
|
||||
"\n",
|
||||
"#linear\n",
|
||||
"y=2*x+s\n",
|
||||
"\n",
|
||||
"#Tenth Order\n",
|
||||
"#y=2*x-10*x**5+15*x**10+s\n",
|
||||
"\n",
|
||||
"p1=plt.plot(x,y, \"o\",ms=15, label='Training')\n",
|
||||
"\n",
|
||||
"#Linear Regression\n",
|
||||
"# Create linear regression object\n",
|
||||
"clf = linear_model.LinearRegression()\n",
|
||||
"\n",
|
||||
"# Train the model using the training sets\n",
|
||||
"clf.fit(x[:, np.newaxis], y)\n",
|
||||
"# The coefficients\n",
|
||||
"\n",
|
||||
"xplot=np.linspace(0.02,0.98,200)\n",
|
||||
"linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label='Linear')\n",
|
||||
"\n",
|
||||
"#Polynomial Regression\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"poly3 = PolynomialFeatures(degree=3)\n",
|
||||
"X = poly3.fit_transform(x[:,np.newaxis])\n",
|
||||
"clf3 = linear_model.LinearRegression()\n",
|
||||
"clf3.fit(X,y)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Xplot=poly3.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label='Poly 3')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#poly5 = PolynomialFeatures(degree=5)\n",
|
||||
"#X = poly5.fit_transform(x[:,np.newaxis])\n",
|
||||
"#clf5 = linear_model.LinearRegression()\n",
|
||||
"#clf5.fit(X,y)\n",
|
||||
"\n",
|
||||
"#Xplot=poly5.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)\n",
|
||||
"\n",
|
||||
"poly10 = PolynomialFeatures(degree=10)\n",
|
||||
"X = poly10.fit_transform(x[:,np.newaxis])\n",
|
||||
"clf10 = linear_model.LinearRegression()\n",
|
||||
"clf10.fit(X,y)\n",
|
||||
"\n",
|
||||
"Xplot=poly10.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label='Poly 10')\n",
|
||||
"\n",
|
||||
"axes = plt.gca()\n",
|
||||
"axes.set_ylim([-7,7])\n",
|
||||
"\n",
|
||||
"handles, labels=axes.get_legend_handles_labels()\n",
|
||||
"plt.legend(handles,labels, loc='lower center')\n",
|
||||
"plt.xlabel(\"$x$\")\n",
|
||||
"plt.ylabel(\"$y$\")\n",
|
||||
"Title=\"$N=$\"+str(N_train)+\", $\\sigma=$\"+str(sigma_train)\n",
|
||||
"plt.title(Title+\" (train)\")\n",
|
||||
"plt.tight_layout()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- !split -->\n",
|
||||
"## Generating test data"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1826,6 +1871,157 @@
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Generate Test Data\n",
|
||||
"\n",
|
||||
"#Number of test data\n",
|
||||
"N_test=20\n",
|
||||
"\n",
|
||||
"sigma_test=sigma_train\n",
|
||||
"\n",
|
||||
"max_x=1.2\n",
|
||||
"x_test=max_x*np.random.random(N_test)\n",
|
||||
"# Draw random noise\n",
|
||||
"s_test = sigma_test*np.random.randn(N_test)\n",
|
||||
"\n",
|
||||
"#Linear\n",
|
||||
"y_test=2*x_test+s_test\n",
|
||||
"#Tenth order\n",
|
||||
"#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test\n",
|
||||
"\n",
|
||||
"#Make design matrices for prediction\n",
|
||||
"x_plot=np.linspace(0,max_x, 200)\n",
|
||||
"X3 = poly3.fit_transform(x_plot[:,np.newaxis])\n",
|
||||
"X10 = poly10.fit_transform(x_plot[:,np.newaxis])\n",
|
||||
"\n",
|
||||
"%matplotlib notebook\n",
|
||||
"\n",
|
||||
"fig = plt.figure() \n",
|
||||
"p1=plt.plot(x_test,y_test.transpose(), 'o', ms=12, label='data')\n",
|
||||
"p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label='linear')\n",
|
||||
"p3=plt.plot(x_plot,clf3.predict(X3), label='3rd order')\n",
|
||||
"p10=plt.plot(x_plot,clf10.predict(X10), label='10th order')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.legend(loc=2)\n",
|
||||
"plt.xlabel('$x$')\n",
|
||||
"plt.ylabel('$y$')\n",
|
||||
"plt.legend(loc='best')\n",
|
||||
"plt.title(Title+\" (pred.)\")\n",
|
||||
"plt.tight_layout()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## How can we effectively evaluate the various models?\n",
|
||||
"\n",
|
||||
"In Ridge regression and the subsequent discussion of its properties\n",
|
||||
"the bias or penalty parameter is considered known or `given'. In\n",
|
||||
"practice, it is unknown and the user needs to make an informed\n",
|
||||
"decision on its value. How do we do that? Much of the same considerations apply to the Lasso method. \n",
|
||||
"\n",
|
||||
"## Code examples for Ridge and Lasso Regression"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np\n",
|
||||
"from sklearn import linear_model\n",
|
||||
"from sklearn.linear_model import LinearRegression\n",
|
||||
"from sklearn.metrics import mean_squared_error, r2_score\n",
|
||||
"\n",
|
||||
"#creating data with random noise\n",
|
||||
"x=np.arange(50)\n",
|
||||
"\n",
|
||||
"delta=np.random.uniform(-2.5,2.5, size=(50))\n",
|
||||
"np.random.shuffle(delta)\n",
|
||||
"y =0.5*x+5+delta\n",
|
||||
"\n",
|
||||
"#arranging data into 2x50 matrix\n",
|
||||
"a=np.array(x) #inputs\n",
|
||||
"b=np.array(y) #outputs\n",
|
||||
"\n",
|
||||
"#Split into training and test\n",
|
||||
"X_train=a[:37, np.newaxis]\n",
|
||||
"X_test=a[37:, np.newaxis]\n",
|
||||
"y_train=b[:37]\n",
|
||||
"y_test=b[37:]\n",
|
||||
"\n",
|
||||
"print (\"X_train: \", X_train.shape)\n",
|
||||
"print (\"y_train: \", y_train.shape)\n",
|
||||
"print (\"X_test: \", X_test.shape)\n",
|
||||
"print (\"y_test: \", y_test.shape)\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Ordinary Least Squares\")\n",
|
||||
"#Add Ordinary Least Squares fit\n",
|
||||
"reg=LinearRegression()\n",
|
||||
"reg.fit(X_train, y_train)\n",
|
||||
"pred=reg.predict(X_test)\n",
|
||||
"print (\"Prediction Shape: \", pred.shape)\n",
|
||||
"\n",
|
||||
"print('Coefficients: \\n', reg.coef_)\n",
|
||||
"# The mean squared error\n",
|
||||
"print(\"Mean squared error: %.2f\"\n",
|
||||
" % mean_squared_error(y_test, pred))\n",
|
||||
"# Explained variance score: 1 is perfect prediction\n",
|
||||
"print('Variance score: %.2f' % r2_score(y_test, pred))\n",
|
||||
"\n",
|
||||
"#plot\n",
|
||||
"plt.scatter(X_test,y_test,color='green', label=\"Training Data\")\n",
|
||||
"plt.plot(X_test, pred, color='black', label=\"Fit Line\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Ridge Regression\")\n",
|
||||
"\n",
|
||||
"ridge=linear_model.RidgeCV(alphas=[0.1,1.0,10.0])\n",
|
||||
"ridge.fit(X_train,y_train)\n",
|
||||
"print (\"Ridge Coefficient: \",ridge.coef_)\n",
|
||||
"print (\"Ridge Intercept: \", ridge.intercept_)\n",
|
||||
"#Look into graphing with Ridge fit\n",
|
||||
"\n",
|
||||
"print (\"------------------------------------\")\n",
|
||||
"\n",
|
||||
"print (\"Lasso\")\n",
|
||||
"lasso=linear_model.Lasso(alpha=0.1)\n",
|
||||
"lasso.fit(X_train,y_train)\n",
|
||||
"predl=lasso.predict(X_test)\n",
|
||||
"print(\"Lasso Coefficient: \", lasso.coef_)\n",
|
||||
"print(\"Lasso Intercept: \", lasso.intercept_)\n",
|
||||
"plt.scatter(X_test,y_test,color='green', label=\"Training Data\")\n",
|
||||
"plt.plot(X_test, predl, color='blue', label=\"Lasso\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## A second-order polynomial with Ridge and Lasso"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
@@ -1939,204 +2135,229 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Fitting vs. predicting when data is in the model class\n",
|
||||
"\n",
|
||||
"We start by considering the case\n",
|
||||
"$f(x)=2x$.\n",
|
||||
"\n",
|
||||
"Then the data is clearly generated by a model that is contained within\n",
|
||||
"all three model classes we are using to make predictions (linear\n",
|
||||
"models, third order polynomials, and tenth order polynomials).\n",
|
||||
"\n",
|
||||
"Run the code for the following cases:\n",
|
||||
"\n",
|
||||
"1. For $f(x)=2x$ , $Ntrain=10$ and $\\sigma =0$ (noiseless case), train the three classes of models (linear, third-order polynomial, and tenth order polynomial) for a training set when $x \\in [0,1]$ . Make graphs comparing fits for different order of polynomials. Which model fits the data the best?\n",
|
||||
"\n",
|
||||
"2. Do you think that the data that has the least error on the training set will also make the best predictions? Why or why not? Can you try to discuss and formalize your intuition? What can go right and what can go wrong?\n",
|
||||
"\n",
|
||||
"3. Check your answer by seeing how well your fits predict newly generated test data (including on data outside the range you fit on, for example $x \\in [0,1.2]$ ) using the code below. How well do you do on points in the range of x where you trained the model? How about points outside the original training data set?\n",
|
||||
"\n",
|
||||
"4. Repeat the above for $f(x)=2x$ , $Ntrain=10$ , and $\\sigma=1$ . What changes?\n",
|
||||
"\n",
|
||||
"Repeat the exercises above for $f(x)=2x$ , $Ntrain=100$ , and $\\sigma=1$ . What changes?\n",
|
||||
"Summarize what you have learned about the relationship between model complexity (number of parameters), goodness of fit on training data, and the ability to predict well.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Fitting versus predicting when data is not in the model class\n",
|
||||
"\n",
|
||||
"Thus far, we have considered the case where the data is generated using a model contained in the model class. Now consider $f(x)=2x-10x^5+15x^{10}$ . Notice that the for linear and third-order polynomial the true model $f(x)$ is not contained in model class.\n",
|
||||
"\n",
|
||||
"1. Do better fits lead to better predictions?\n",
|
||||
"\n",
|
||||
"2. What is the relationship between the true model for generating the data and the model class that has the most predictive power? How is this related to the model complexity? How does this depend on the number of data points $Ntrain$ and $\\sigma$?\n",
|
||||
"\n",
|
||||
"Summarize what you think you learned about the relationship of knowing the true model class and predictive power.\n",
|
||||
"\n",
|
||||
"## The code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import sklearn as sk\n",
|
||||
"from sklearn import datasets, linear_model\n",
|
||||
"from sklearn.preprocessing import PolynomialFeatures\n",
|
||||
"\n",
|
||||
"import matplotlib as mpl\n",
|
||||
"from matplotlib import pyplot as plt\n",
|
||||
"\n",
|
||||
"%matplotlib notebook\n",
|
||||
"\n",
|
||||
"# The Training Data\n",
|
||||
"\n",
|
||||
"N_train=100\n",
|
||||
"\n",
|
||||
"sigma_train=1;\n",
|
||||
"\n",
|
||||
"# Train on integers\n",
|
||||
"x=np.linspace(0.05,0.95,N_train)\n",
|
||||
"# Draw random noise\n",
|
||||
"s = sigma_train*np.random.randn(N_train)\n",
|
||||
"\n",
|
||||
"#linear\n",
|
||||
"y=2*x+s\n",
|
||||
"\n",
|
||||
"#Tenth Order\n",
|
||||
"#y=2*x-10*x**5+15*x**10+s\n",
|
||||
"\n",
|
||||
"p1=plt.plot(x,y, \"o\",ms=15, label='Training')\n",
|
||||
"\n",
|
||||
"#Linear Regression\n",
|
||||
"# Create linear regression object\n",
|
||||
"clf = linear_model.LinearRegression()\n",
|
||||
"\n",
|
||||
"# Train the model using the training sets\n",
|
||||
"clf.fit(x[:, np.newaxis], y)\n",
|
||||
"# The coefficients\n",
|
||||
"\n",
|
||||
"xplot=np.linspace(0.02,0.98,200)\n",
|
||||
"linear_plot=plt.plot(xplot, clf.predict(xplot[:, np.newaxis]),label='Linear')\n",
|
||||
"\n",
|
||||
"#Polynomial Regression\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"poly3 = PolynomialFeatures(degree=3)\n",
|
||||
"X = poly3.fit_transform(x[:,np.newaxis])\n",
|
||||
"clf3 = linear_model.LinearRegression()\n",
|
||||
"clf3.fit(X,y)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Xplot=poly3.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"poly3_plot=plt.plot(xplot, clf3.predict(Xplot), label='Poly 3')\n",
|
||||
"## Resampling methods\n",
|
||||
"Resampling methods are an indispensable tool in modern\n",
|
||||
"statistics. They involve repeatedly drawing samples from a training\n",
|
||||
"set and refitting a model of interest on each sample in order to\n",
|
||||
"obtain additional information about the fitted model. For example, in\n",
|
||||
"order to estimate the variability of a linear regression fit, we can\n",
|
||||
"repeatedly draw different samples from the training data, fit a linear\n",
|
||||
"regression to each new sample, and then examine the extent to which\n",
|
||||
"the resulting fits differ. Such an approach may allow us to obtain\n",
|
||||
"information that would not be available from fitting the model only\n",
|
||||
"once using the original training sample.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#poly5 = PolynomialFeatures(degree=5)\n",
|
||||
"#X = poly5.fit_transform(x[:,np.newaxis])\n",
|
||||
"#clf5 = linear_model.LinearRegression()\n",
|
||||
"#clf5.fit(X,y)\n",
|
||||
"## Resampling approaches can be computationally expensive\n",
|
||||
"Resampling approaches can be computationally expensive, because they\n",
|
||||
"involve fitting the same statistical method multiple times using\n",
|
||||
"different subsets of the training data. However, due to recent\n",
|
||||
"advances in computing power, the computational requirements of\n",
|
||||
"resampling methods generally are not prohibitive. In this chapter, we\n",
|
||||
"discuss two of the most commonly used resampling methods,\n",
|
||||
"cross-validation and the bootstrap. Both methods are important tools\n",
|
||||
"in the practical application of many statistical learning\n",
|
||||
"procedures. For example, cross-validation can be used to estimate the\n",
|
||||
"test error associated with a given statistical learning method in\n",
|
||||
"order to evaluate its performance, or to select the appropriate level\n",
|
||||
"of flexibility. The process of evaluating a model’s performance is\n",
|
||||
"known as model assessment, whereas the process of selecting the proper\n",
|
||||
"level of flexibility for a model is known as model selection. The\n",
|
||||
"bootstrap is widely used.\n",
|
||||
"\n",
|
||||
"#Xplot=poly5.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"#plt.plot(xplot, clf5.predict(Xplot), 'r--',linewidth=1)\n",
|
||||
"\n",
|
||||
"poly10 = PolynomialFeatures(degree=10)\n",
|
||||
"X = poly10.fit_transform(x[:,np.newaxis])\n",
|
||||
"clf10 = linear_model.LinearRegression()\n",
|
||||
"clf10.fit(X,y)\n",
|
||||
"\n",
|
||||
"Xplot=poly10.fit_transform(xplot[:,np.newaxis])\n",
|
||||
"poly10_plot=plt.plot(xplot, clf10.predict(Xplot), label='Poly 10')\n",
|
||||
"\n",
|
||||
"axes = plt.gca()\n",
|
||||
"axes.set_ylim([-7,7])\n",
|
||||
"## Log-likelihood\n",
|
||||
"\n",
|
||||
"handles, labels=axes.get_legend_handles_labels()\n",
|
||||
"plt.legend(handles,labels, loc='lower center')\n",
|
||||
"plt.xlabel(\"$x$\")\n",
|
||||
"plt.ylabel(\"$y$\")\n",
|
||||
"Title=\"$N=$\"+str(N_train)+\", $\\sigma=$\"+str(sigma_train)\n",
|
||||
"plt.title(Title+\" (train)\")\n",
|
||||
"plt.tight_layout()\n",
|
||||
"plt.show()"
|
||||
"A popular strategy is to choose a penalty parameter that yields a good\n",
|
||||
"but parsimonious model. Information criteria measure the balance\n",
|
||||
"between model fit and model complexity. One possibility is Aikaike's\n",
|
||||
"information criterion (AIC).\n",
|
||||
"The AIC measures model fit by the log-likelihood\n",
|
||||
"and model complexity is measured by the number of parameters used by\n",
|
||||
"the model. The number of model parameters in regular regression simply\n",
|
||||
"corresponds to the number of covariates in the model. Or, by the\n",
|
||||
"degrees of freedom consumed by the model, which is equivalent to the\n",
|
||||
"trace of the hat matrix. For ridge regression it thus seems natural to\n",
|
||||
"define model complexity analogously by the trace of the ridge hat\n",
|
||||
"matrix. This yields the AIC for the linear regression model with ridge\n",
|
||||
"estimates:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"$$\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\mbox{AIC}(\\lambda) & = 2 \\, p - 2 \\log(\\hat{L})\n",
|
||||
"\\\\\n",
|
||||
"& = 2 \\, \\mbox{tr} [\\mathbf{H}(\\lambda)] - 2 \\log\\{L[\\hat{\\beta}(\\lambda), \\hat{\\sigma}^2(\\lambda)]\\}\n",
|
||||
"\\\\\n",
|
||||
"& = 2 \\, \\sum_{j=1}^p \\frac{d_{jj}^2}{d_{jj}^2 + \\lambda}\n",
|
||||
"+ 2 n \\, \\log[\\sqrt{2 \\, \\pi} \\, \\hat{\\sigma}(\\lambda)] + \\frac{1}{\\hat{\\sigma}^2(\\lambda)} \\sum_{i=1}^n [y_i - \\mathbf{X}_{i, \\ast} \\, \\hat{\\beta}(\\lambda)]^2.\n",
|
||||
"\\end{align*}\n",
|
||||
"$$"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The value of $\\lambda$ which minimizes $\\mbox{AIC}(\\lambda)$ corresponds to the `optimal' balance of model complexity and overfitting.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"<!-- !split -->\n",
|
||||
"## Generating test data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Generate Test Data\n",
|
||||
"## Cross-validation\n",
|
||||
"\n",
|
||||
"#Number of test data\n",
|
||||
"N_test=20\n",
|
||||
"\n",
|
||||
"sigma_test=sigma_train\n",
|
||||
"\n",
|
||||
"max_x=1.2\n",
|
||||
"x_test=max_x*np.random.random(N_test)\n",
|
||||
"# Draw random noise\n",
|
||||
"s_test = sigma_test*np.random.randn(N_test)\n",
|
||||
"\n",
|
||||
"#Linear\n",
|
||||
"y_test=2*x_test+s_test\n",
|
||||
"#Tenth order\n",
|
||||
"#y_test=2*x_test-10*x_test**5+15*x_test**10+s_test\n",
|
||||
"\n",
|
||||
"#Make design matrices for prediction\n",
|
||||
"x_plot=np.linspace(0,max_x, 200)\n",
|
||||
"X3 = poly3.fit_transform(x_plot[:,np.newaxis])\n",
|
||||
"X10 = poly10.fit_transform(x_plot[:,np.newaxis])\n",
|
||||
"\n",
|
||||
"%matplotlib notebook\n",
|
||||
"\n",
|
||||
"fig = plt.figure() \n",
|
||||
"p1=plt.plot(x_test,y_test.transpose(), 'o', ms=12, label='data')\n",
|
||||
"p2=plt.plot(x_plot,clf.predict(x_plot[:,np.newaxis]), label='linear')\n",
|
||||
"p3=plt.plot(x_plot,clf3.predict(X3), label='3rd order')\n",
|
||||
"p10=plt.plot(x_plot,clf10.predict(X10), label='10th order')\n",
|
||||
"Instead of choosing the penalty parameter to balance model fit with\n",
|
||||
"model complexity, cross-validation requires it (i.e. the penalty\n",
|
||||
"parameter) to yield a model with good prediction\n",
|
||||
"performance. Commonly, this performance is evaluated on novel\n",
|
||||
"data. Novel data need not be easy to come by and one has to make do\n",
|
||||
"with the data at hand. The setting of `original' and novel data is\n",
|
||||
"then mimicked by sample splitting: the data set is divided into two\n",
|
||||
"(groups of samples). One of these two data sets, called the *training\n",
|
||||
"set*, plays the role of `original' data on which the model is\n",
|
||||
"built. The second of these data sets, called the *test set*, plays the\n",
|
||||
"role of the `novel' data and is used to evaluate the prediction\n",
|
||||
"performance (often operationalized as the log-likelihood or the\n",
|
||||
"prediction error or its square or the R2 score) of the model built on the training data set. This\n",
|
||||
"procedure (model building and prediction evaluation on training and\n",
|
||||
"test set, respectively) is done for a collection of possible penalty\n",
|
||||
"parameter choices. The penalty parameter that yields the model with\n",
|
||||
"the best prediction performance is to be preferred. The thus obtained\n",
|
||||
"performance evaluation depends on the actual split of the data set. To\n",
|
||||
"remove this dependence the data set is split many times into a\n",
|
||||
"training and test set. For each split the model parameters are\n",
|
||||
"estimated for all choices of $\\lambda$ using the training data and\n",
|
||||
"estimated parameters are evaluated on the corresponding test set. The\n",
|
||||
"penalty parameter that on average over the test sets performs best (in\n",
|
||||
"some sense) is then selected.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.legend(loc=2)\n",
|
||||
"plt.xlabel('$x$')\n",
|
||||
"plt.ylabel('$y$')\n",
|
||||
"plt.legend(loc='best')\n",
|
||||
"plt.title(Title+\" (pred.)\")\n",
|
||||
"plt.tight_layout()\n",
|
||||
"plt.show()\n",
|
||||
"## Computationally expensive\n",
|
||||
"\n",
|
||||
"#Linear Filename\n",
|
||||
"#filename_test=Title+\"pred-linear.pdf\"\n",
|
||||
"#Tenth Order Filename\n",
|
||||
"#filename_test=Title+\"pred-o10.pdf\"\n",
|
||||
"#plt.savefig(filename_test)\n",
|
||||
"#plt.ylim((-6,12))"
|
||||
"The validation set approach is conceptually simple and is easy to implement. But it has two potential drawbacks:\n",
|
||||
"\n",
|
||||
"* The validation estimate of the test error rate can be highly variable, depending on precisely which observations are included in the training set and which observations are included in the validation set.\n",
|
||||
"\n",
|
||||
"* In the validation approach, only a subset of the observations, those that are included in the training set rather than in the validation set are used to fit the model. Since statistical methods tend to perform worse when trained on fewer observations, this suggests that the validation set error rate may tend to overestimate the test error rate for the model fit on the entire data set.\n",
|
||||
"\n",
|
||||
"<!-- !split -->\n",
|
||||
"## Various steps in cross-validation\n",
|
||||
"\n",
|
||||
"When the repetitive splitting of the data set is done randomly,\n",
|
||||
"samples may accidently end up in a fast majority of the splits in\n",
|
||||
"either training or test set. Such samples may have an unbalanced\n",
|
||||
"influence on either model building or prediction evaluation. To avoid\n",
|
||||
"this $k$-fold cross-validation structures the data splitting. The\n",
|
||||
"samples are divided into $k$ more or less equally sized exhaustive and\n",
|
||||
"mutually exclusive subsets. In turn (at each split) one of these\n",
|
||||
"subsets plays the role of the test set while the union of the\n",
|
||||
"remaining subsets constitutes the training set. Such a splitting\n",
|
||||
"warrants a balanced representation of each sample in both training and\n",
|
||||
"test set over the splits. Still the division into the $k$ subsets\n",
|
||||
"involves a degree of randomness. This may be fully excluded when\n",
|
||||
"choosing $k=n$. This particular case is referred to as leave-one-out\n",
|
||||
"cross-validation (LOOCV). \n",
|
||||
"\n",
|
||||
"<!-- !split -->\n",
|
||||
"## How to set up the cross-validation for Ridge and/or Lasso\n",
|
||||
"\n",
|
||||
"1. Define a range of interest for the penalty parameter.\n",
|
||||
"\n",
|
||||
"2. Divide the data set into training and test set comprising samples $\\{1, \\ldots, n\\} \\setminus i$ and $\\{ i \\}$, respectively.\n",
|
||||
"\n",
|
||||
"3. Fit the linear regression model by means of ridge estimation for each $\\lambda$ in the grid using the training set as"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Lasso regression\n",
|
||||
"$$\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\hat{\\beta}_{-i}(\\lambda) & = ( \\hat{X}_{-i, \\ast}^{\\top}\n",
|
||||
"\\hat{X}_{-i, \\ast} + \\lambda \\hat{I}_{pp})^{-1}\n",
|
||||
"\\hat{X}_{-i, \\ast}^{\\top} \\hat{y}_{-i}\n",
|
||||
"\\end{align*}\n",
|
||||
"$$"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"and the corresponding estimate of the error variance $\\hat{\\sigma}_{-i}^2(\\lambda)$.\n",
|
||||
"\n",
|
||||
"1. Evaluate the prediction performance of these models on the test set by $\\log\\{L[y_i, \\hat{X}_{i, \\ast}; \\hat{\\beta}_{-i}(\\lambda), \\hat{\\sigma}_{-i}^2(\\lambda)]\\}$. Or, by the prediction error $|y_i - \\hat{X}_{i, \\ast} \\hat{\\beta}_{-i}(\\lambda)|$, the relative error, the error squared or the R2 score function.\n",
|
||||
"\n",
|
||||
"2. Repeat steps 1) to 3) such that each sample plays the role of the test set once.\n",
|
||||
"\n",
|
||||
"3. Average the prediction performances of the test sets at each grid point of the penalty bias/parameter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"$$\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\frac{1}{n} \\sum_{i = 1}^n \\log\\{L[Y_i, \\mathbf{X}_{i, \\ast}; \\hat{\\beta}_{-i}(\\lambda), \\hat{\\sigma}_{-i}^2(\\lambda)]\\}.\n",
|
||||
"\\end{align*}\n",
|
||||
"$$"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The quantity above is called the *cross-validated log-likelihood*. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data.\n",
|
||||
"\n",
|
||||
"1. The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.\n",
|
||||
"\n",
|
||||
"## Predicted Residual Error Sum of Squares\n",
|
||||
"Another approach in the LOOCV scheme is to the use the so-called Predicted Residual Error Sum of Squares (PRESS). \n",
|
||||
"\n",
|
||||
"We can define the optimal penalty parameter to minimize"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"$$\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\lambda_{\\mbox{{\\tiny opt}}} = \\arg \\min_{\\lambda} \\frac{1}{n} \\sum_{i=1}^n [y_i - \\hat{X}_{i, \\ast} \\hat{\\beta}_{-i}(\\lambda)]^2.\n",
|
||||
"\\end{align*}\n",
|
||||
"$$"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The LOOCV prediction performance can be\n",
|
||||
"expressed analytically in terms of the known quantities derived from\n",
|
||||
"the design matrix and the parameters $\\beta$.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Logistic regression"
|
||||
"\n",
|
||||
"## Bootstrap\n",
|
||||
"Bootstrapping is a nonparametric approach to statistical inference\n",
|
||||
"that substitutes computation for more traditional distributional\n",
|
||||
"assumptions and asymptotic results. Bootstrapping offers a number of\n",
|
||||
"advantages: \n",
|
||||
"1. The bootstrap is quite general, although there are some cases in which it fails. \n",
|
||||
"\n",
|
||||
"2. 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. \n",
|
||||
"\n",
|
||||
"3. It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically. \n",
|
||||
"\n",
|
||||
"4. It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples)."
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -964,85 +964,6 @@ We have then
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Code examples for Ridge and Lasso Regression =====
|
||||
|
||||
!bc pycod
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from sklearn import linear_model
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.metrics import mean_squared_error, r2_score
|
||||
|
||||
#creating data with random noise
|
||||
x=np.arange(50)
|
||||
|
||||
delta=np.random.uniform(-2.5,2.5, size=(50))
|
||||
np.random.shuffle(delta)
|
||||
y =0.5*x+5+delta
|
||||
|
||||
#arranging data into 2x50 matrix
|
||||
a=np.array(x) #inputs
|
||||
b=np.array(y) #outputs
|
||||
|
||||
#Split into training and test
|
||||
X_train=a[:37, np.newaxis]
|
||||
X_test=a[37:, np.newaxis]
|
||||
y_train=b[:37]
|
||||
y_test=b[37:]
|
||||
|
||||
print ("X_train: ", X_train.shape)
|
||||
print ("y_train: ", y_train.shape)
|
||||
print ("X_test: ", X_test.shape)
|
||||
print ("y_test: ", y_test.shape)
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Ordinary Least Squares")
|
||||
#Add Ordinary Least Squares fit
|
||||
reg=LinearRegression()
|
||||
reg.fit(X_train, y_train)
|
||||
pred=reg.predict(X_test)
|
||||
print ("Prediction Shape: ", pred.shape)
|
||||
|
||||
print('Coefficients: \n', reg.coef_)
|
||||
# The mean squared error
|
||||
print("Mean squared error: %.2f"
|
||||
% mean_squared_error(y_test, pred))
|
||||
# Explained variance score: 1 is perfect prediction
|
||||
print('Variance score: %.2f' % r2_score(y_test, pred))
|
||||
|
||||
#plot
|
||||
plt.scatter(X_test,y_test,color='green', label="Training Data")
|
||||
plt.plot(X_test, pred, color='black', label="Fit Line")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Ridge Regression")
|
||||
|
||||
ridge=linear_model.RidgeCV(alphas=[0.1,1.0,10.0])
|
||||
ridge.fit(X_train,y_train)
|
||||
print ("Ridge Coefficient: ",ridge.coef_)
|
||||
print ("Ridge Intercept: ", ridge.intercept_)
|
||||
#Look into graphing with Ridge fit
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Lasso")
|
||||
lasso=linear_model.Lasso(alpha=0.1)
|
||||
lasso.fit(X_train,y_train)
|
||||
predl=lasso.predict(X_test)
|
||||
print("Lasso Coefficient: ", lasso.coef_)
|
||||
print("Lasso Intercept: ", lasso.intercept_)
|
||||
plt.scatter(X_test,y_test,color='green', label="Training Data")
|
||||
plt.plot(X_test, predl, color='blue', label="Lasso")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1121,118 +1042,6 @@ where $\hat{I}$ is the identity matrix.
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== A second-order polynomial with Ridge and Lasso =====
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.linear_model import Ridge
|
||||
from sklearn.metrics import r2_score
|
||||
|
||||
np.random.seed(4155)
|
||||
|
||||
n_samples = 100
|
||||
|
||||
x = np.random.rand(n_samples,1)
|
||||
y = 5*x*x + 0.1*np.random.rand(n_samples,1)
|
||||
|
||||
# Centering x and y.
|
||||
x_ = x - np.mean(x)
|
||||
y_ = y - np.mean(y) # beta_0 = mean(y)
|
||||
|
||||
X = np.c_[np.ones((n_samples,1)), x, x**2]
|
||||
X_ = np.c_[x_, x_**2]
|
||||
|
||||
|
||||
### 1.
|
||||
lmb_values = [1e-4, 1e-3, 1e-2, 10, 1e2, 1e4]
|
||||
num_values = len(lmb_values)
|
||||
|
||||
## Ridge-regression of centered and not centered data
|
||||
beta_ridge = np.zeros((3,num_values))
|
||||
beta_ridge_centered = np.zeros((3,num_values))
|
||||
|
||||
I3 = np.eye(3)
|
||||
I2 = np.eye(2)
|
||||
|
||||
for i,lmb in enumerate(lmb_values):
|
||||
beta_ridge[:,i] = (np.linalg.inv( X.T @ X + lmb*I3) @ X.T @ y).flatten()
|
||||
beta_ridge_centered[1:,i] = (np.linalg.inv( X_.T @ X_ + lmb*I2) @ X_.T @ y_).flatten()
|
||||
|
||||
# sett beta_0 = np.mean(y)
|
||||
beta_ridge_centered[0,:] = np.mean(y)
|
||||
|
||||
## OLS (ordinary least squares) solution
|
||||
beta_ls = np.linalg.inv( X.T @ X ) @ X.T @ y
|
||||
|
||||
## Evaluate the models
|
||||
pred_ls = X @ beta_ls
|
||||
pred_ridge = X @ beta_ridge
|
||||
pred_ridge_centered = X_ @ beta_ridge_centered[1:] + beta_ridge_centered[0,:]
|
||||
|
||||
## Plot the results
|
||||
|
||||
# Sorting
|
||||
sort_ind = np.argsort(x[:,0])
|
||||
|
||||
x_plot = x[sort_ind,0]
|
||||
x_centered_plot = x_[sort_ind,0]
|
||||
|
||||
pred_ls_plot = pred_ls[sort_ind,0]
|
||||
pred_ridge_plot = pred_ridge[sort_ind,:]
|
||||
pred_ridge_centered_plot = pred_ridge_centered[sort_ind,:]
|
||||
|
||||
# Plott not centered
|
||||
plt.plot(x_plot,pred_ls_plot,label='ls')
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_plot,pred_ridge_plot[:,i],label='ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x,y,'ro')
|
||||
|
||||
plt.title('linear regression on un-centered data')
|
||||
plt.legend()
|
||||
|
||||
# Plott centered
|
||||
plt.figure()
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_centered_plot,pred_ridge_centered_plot[:,i],label='ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x_,y,'ro')
|
||||
|
||||
plt.title('linear regression on centered data')
|
||||
plt.legend()
|
||||
|
||||
|
||||
# 2.
|
||||
|
||||
pred_ridge_scikit = np.zeros((n_samples,num_values))
|
||||
for i,lmb in enumerate(lmb_values):
|
||||
pred_ridge_scikit[:,i] = (Ridge(alpha=lmb,fit_intercept=False).fit(X,y).predict(X)).flatten() # fit_intercept=False fordi bias er allerede i X
|
||||
|
||||
plt.figure()
|
||||
|
||||
plt.plot(x_plot,pred_ls_plot,label='ls')
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_plot,pred_ridge_scikit[sort_ind,i],label='scikit-ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x,y,'ro')
|
||||
plt.legend()
|
||||
plt.title('linear regression using scikit')
|
||||
|
||||
plt.show()
|
||||
|
||||
### R2-score of the results
|
||||
for i in range(num_values):
|
||||
print('lambda = %g'%lmb_values[i])
|
||||
print('r2 for scikit: %g'%r2_score(y,pred_ridge_scikit[:,i]))
|
||||
print('r2 for own code, not centered: %g'%r2_score(y,pred_ridge[:,i]))
|
||||
print('r2 for own, centered: %g\n'%r2_score(y,pred_ridge_centered[:,i]))
|
||||
|
||||
|
||||
!ec
|
||||
|
||||
|
||||
!split
|
||||
@@ -1265,7 +1074,7 @@ o What is the relationship between the true model for generating the data and th
|
||||
Summarize what you think you learned about the relationship of knowing the true model class and predictive power.
|
||||
|
||||
!split
|
||||
===== The code =====
|
||||
===== An example code without the model assessment part =====
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
@@ -1394,18 +1203,396 @@ plt.title(Title+" (pred.)")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
#Linear Filename
|
||||
#filename_test=Title+"pred-linear.pdf"
|
||||
#Tenth Order Filename
|
||||
#filename_test=Title+"pred-o10.pdf"
|
||||
#plt.savefig(filename_test)
|
||||
#plt.ylim((-6,12))
|
||||
|
||||
!ec
|
||||
|
||||
!split
|
||||
===== Lasso regression =====
|
||||
===== How can we effectively evaluate the various models? =====
|
||||
|
||||
In Ridge regression and the subsequent discussion of its properties
|
||||
the bias or penalty parameter is considered known or `given'. In
|
||||
practice, it is unknown and the user needs to make an informed
|
||||
decision on its value. How do we do that? Much of the same considerations apply to the Lasso method.
|
||||
|
||||
!split
|
||||
===== Code examples for Ridge and Lasso Regression =====
|
||||
|
||||
!bc pycod
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from sklearn import linear_model
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.metrics import mean_squared_error, r2_score
|
||||
|
||||
#creating data with random noise
|
||||
x=np.arange(50)
|
||||
|
||||
delta=np.random.uniform(-2.5,2.5, size=(50))
|
||||
np.random.shuffle(delta)
|
||||
y =0.5*x+5+delta
|
||||
|
||||
#arranging data into 2x50 matrix
|
||||
a=np.array(x) #inputs
|
||||
b=np.array(y) #outputs
|
||||
|
||||
#Split into training and test
|
||||
X_train=a[:37, np.newaxis]
|
||||
X_test=a[37:, np.newaxis]
|
||||
y_train=b[:37]
|
||||
y_test=b[37:]
|
||||
|
||||
print ("X_train: ", X_train.shape)
|
||||
print ("y_train: ", y_train.shape)
|
||||
print ("X_test: ", X_test.shape)
|
||||
print ("y_test: ", y_test.shape)
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Ordinary Least Squares")
|
||||
#Add Ordinary Least Squares fit
|
||||
reg=LinearRegression()
|
||||
reg.fit(X_train, y_train)
|
||||
pred=reg.predict(X_test)
|
||||
print ("Prediction Shape: ", pred.shape)
|
||||
|
||||
print('Coefficients: \n', reg.coef_)
|
||||
# The mean squared error
|
||||
print("Mean squared error: %.2f"
|
||||
% mean_squared_error(y_test, pred))
|
||||
# Explained variance score: 1 is perfect prediction
|
||||
print('Variance score: %.2f' % r2_score(y_test, pred))
|
||||
|
||||
#plot
|
||||
plt.scatter(X_test,y_test,color='green', label="Training Data")
|
||||
plt.plot(X_test, pred, color='black', label="Fit Line")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Ridge Regression")
|
||||
|
||||
ridge=linear_model.RidgeCV(alphas=[0.1,1.0,10.0])
|
||||
ridge.fit(X_train,y_train)
|
||||
print ("Ridge Coefficient: ",ridge.coef_)
|
||||
print ("Ridge Intercept: ", ridge.intercept_)
|
||||
#Look into graphing with Ridge fit
|
||||
|
||||
print ("------------------------------------")
|
||||
|
||||
print ("Lasso")
|
||||
lasso=linear_model.Lasso(alpha=0.1)
|
||||
lasso.fit(X_train,y_train)
|
||||
predl=lasso.predict(X_test)
|
||||
print("Lasso Coefficient: ", lasso.coef_)
|
||||
print("Lasso Intercept: ", lasso.intercept_)
|
||||
plt.scatter(X_test,y_test,color='green', label="Training Data")
|
||||
plt.plot(X_test, predl, color='blue', label="Lasso")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Logistic regression =====
|
||||
===== A second-order polynomial with Ridge and Lasso =====
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.linear_model import Ridge
|
||||
from sklearn.metrics import r2_score
|
||||
|
||||
np.random.seed(4155)
|
||||
|
||||
n_samples = 100
|
||||
|
||||
x = np.random.rand(n_samples,1)
|
||||
y = 5*x*x + 0.1*np.random.rand(n_samples,1)
|
||||
|
||||
# Centering x and y.
|
||||
x_ = x - np.mean(x)
|
||||
y_ = y - np.mean(y) # beta_0 = mean(y)
|
||||
|
||||
X = np.c_[np.ones((n_samples,1)), x, x**2]
|
||||
X_ = np.c_[x_, x_**2]
|
||||
|
||||
|
||||
### 1.
|
||||
lmb_values = [1e-4, 1e-3, 1e-2, 10, 1e2, 1e4]
|
||||
num_values = len(lmb_values)
|
||||
|
||||
## Ridge-regression of centered and not centered data
|
||||
beta_ridge = np.zeros((3,num_values))
|
||||
beta_ridge_centered = np.zeros((3,num_values))
|
||||
|
||||
I3 = np.eye(3)
|
||||
I2 = np.eye(2)
|
||||
|
||||
for i,lmb in enumerate(lmb_values):
|
||||
beta_ridge[:,i] = (np.linalg.inv( X.T @ X + lmb*I3) @ X.T @ y).flatten()
|
||||
beta_ridge_centered[1:,i] = (np.linalg.inv( X_.T @ X_ + lmb*I2) @ X_.T @ y_).flatten()
|
||||
|
||||
# sett beta_0 = np.mean(y)
|
||||
beta_ridge_centered[0,:] = np.mean(y)
|
||||
|
||||
## OLS (ordinary least squares) solution
|
||||
beta_ls = np.linalg.inv( X.T @ X ) @ X.T @ y
|
||||
|
||||
## Evaluate the models
|
||||
pred_ls = X @ beta_ls
|
||||
pred_ridge = X @ beta_ridge
|
||||
pred_ridge_centered = X_ @ beta_ridge_centered[1:] + beta_ridge_centered[0,:]
|
||||
|
||||
## Plot the results
|
||||
|
||||
# Sorting
|
||||
sort_ind = np.argsort(x[:,0])
|
||||
|
||||
x_plot = x[sort_ind,0]
|
||||
x_centered_plot = x_[sort_ind,0]
|
||||
|
||||
pred_ls_plot = pred_ls[sort_ind,0]
|
||||
pred_ridge_plot = pred_ridge[sort_ind,:]
|
||||
pred_ridge_centered_plot = pred_ridge_centered[sort_ind,:]
|
||||
|
||||
# Plott not centered
|
||||
plt.plot(x_plot,pred_ls_plot,label='ls')
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_plot,pred_ridge_plot[:,i],label='ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x,y,'ro')
|
||||
|
||||
plt.title('linear regression on un-centered data')
|
||||
plt.legend()
|
||||
|
||||
# Plott centered
|
||||
plt.figure()
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_centered_plot,pred_ridge_centered_plot[:,i],label='ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x_,y,'ro')
|
||||
|
||||
plt.title('linear regression on centered data')
|
||||
plt.legend()
|
||||
|
||||
|
||||
# 2.
|
||||
|
||||
pred_ridge_scikit = np.zeros((n_samples,num_values))
|
||||
for i,lmb in enumerate(lmb_values):
|
||||
pred_ridge_scikit[:,i] = (Ridge(alpha=lmb,fit_intercept=False).fit(X,y).predict(X)).flatten() # fit_intercept=False fordi bias er allerede i X
|
||||
|
||||
plt.figure()
|
||||
|
||||
plt.plot(x_plot,pred_ls_plot,label='ls')
|
||||
|
||||
for i in range(num_values):
|
||||
plt.plot(x_plot,pred_ridge_scikit[sort_ind,i],label='scikit-ridge, lmb=%g'%lmb_values[i])
|
||||
|
||||
plt.plot(x,y,'ro')
|
||||
plt.legend()
|
||||
plt.title('linear regression using scikit')
|
||||
|
||||
plt.show()
|
||||
|
||||
### R2-score of the results
|
||||
for i in range(num_values):
|
||||
print('lambda = %g'%lmb_values[i])
|
||||
print('r2 for scikit: %g'%r2_score(y,pred_ridge_scikit[:,i]))
|
||||
print('r2 for own code, not centered: %g'%r2_score(y,pred_ridge[:,i]))
|
||||
print('r2 for own, centered: %g\n'%r2_score(y,pred_ridge_centered[:,i]))
|
||||
|
||||
|
||||
!ec
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Resampling methods =====
|
||||
!bblock
|
||||
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.
|
||||
!eblock
|
||||
|
||||
!split
|
||||
===== Resampling approaches can be computationally expensive =====
|
||||
!bblock
|
||||
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.
|
||||
!eblock
|
||||
|
||||
|
||||
!split
|
||||
===== Log-likelihood =====
|
||||
|
||||
A popular strategy is to choose a penalty parameter that yields a good
|
||||
but parsimonious model. Information criteria measure the balance
|
||||
between model fit and model complexity. One possibility is Aikaike's
|
||||
information criterion (AIC).
|
||||
The AIC measures model fit by the log-likelihood
|
||||
and model complexity is measured by the number of parameters used by
|
||||
the model. The number of model parameters in regular regression simply
|
||||
corresponds to the number of covariates in the model. Or, by the
|
||||
degrees of freedom consumed by the model, which is equivalent to the
|
||||
trace of the hat matrix. For ridge regression it thus seems natural to
|
||||
define model complexity analogously by the trace of the ridge hat
|
||||
matrix. This yields the AIC for the linear regression model with ridge
|
||||
estimates:
|
||||
|
||||
|
||||
!bt
|
||||
\begin{align*}
|
||||
\mbox{AIC}(\lambda) & = 2 \, p - 2 \log(\hat{L})
|
||||
\\
|
||||
& = 2 \, \mbox{tr} [\mathbf{H}(\lambda)] - 2 \log\{L[\hat{\beta}(\lambda), \hat{\sigma}^2(\lambda)]\}
|
||||
\\
|
||||
& = 2 \, \sum_{j=1}^p \frac{d_{jj}^2}{d_{jj}^2 + \lambda}
|
||||
+ 2 n \, \log[\sqrt{2 \, \pi} \, \hat{\sigma}(\lambda)] + \frac{1}{\hat{\sigma}^2(\lambda)} \sum_{i=1}^n [y_i - \mathbf{X}_{i, \ast} \, \hat{\beta}(\lambda)]^2.
|
||||
\end{align*}
|
||||
!et
|
||||
The value of $\lambda$ which minimizes $\mbox{AIC}(\lambda)$ corresponds to the `optimal' balance of model complexity and overfitting.
|
||||
|
||||
|
||||
!split
|
||||
===== Cross-validation =====
|
||||
|
||||
Instead of choosing the penalty parameter to balance model fit with
|
||||
model complexity, cross-validation requires it (i.e. the penalty
|
||||
parameter) to yield a model with good prediction
|
||||
performance. Commonly, this performance is evaluated on novel
|
||||
data. Novel data need not be easy to come by and one has to make do
|
||||
with the data at hand. The setting of `original' and novel data is
|
||||
then mimicked by sample splitting: the data set is divided into two
|
||||
(groups of samples). One of these two data sets, called the *training
|
||||
set*, plays the role of `original' data on which the model is
|
||||
built. The second of these data sets, called the *test set*, plays the
|
||||
role of the `novel' data and is used to evaluate the prediction
|
||||
performance (often operationalized as the log-likelihood or the
|
||||
prediction error or its square or the R2 score) of the model built on the training data set. This
|
||||
procedure (model building and prediction evaluation on training and
|
||||
test set, respectively) is done for a collection of possible penalty
|
||||
parameter choices. The penalty parameter that yields the model with
|
||||
the best prediction performance is to be preferred. The thus obtained
|
||||
performance evaluation depends on the actual split of the data set. To
|
||||
remove this dependence the data set is split many times into a
|
||||
training and test set. For each split the model parameters are
|
||||
estimated for all choices of $\lambda$ using the training data and
|
||||
estimated parameters are evaluated on the corresponding test set. The
|
||||
penalty parameter that on average over the test sets performs best (in
|
||||
some sense) is then selected.
|
||||
|
||||
|
||||
!split
|
||||
===== Computationally expensive =====
|
||||
|
||||
The validation set approach is conceptually simple and is easy to implement. But it has two potential drawbacks:
|
||||
|
||||
* The validation estimate of the test error rate can be highly variable, depending on precisely which observations are included in the training set and which observations are included in the validation set.
|
||||
|
||||
* In the validation approach, only a subset of the observations, those that are included in the training set rather than in the validation set are used to fit the model. Since statistical methods tend to perform worse when trained on fewer observations, this suggests that the validation set error rate may tend to overestimate the test error rate for the model fit on the entire data set.
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Various steps in cross-validation =====
|
||||
|
||||
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).
|
||||
|
||||
!split
|
||||
===== How to set up the cross-validation for Ridge and/or Lasso =====
|
||||
|
||||
o Define a range of interest for the penalty parameter.
|
||||
|
||||
o Divide the data set into training and test set comprising samples $\{1, \ldots, n\} \setminus i$ and $\{ i \}$, respectively.
|
||||
|
||||
o Fit the linear regression model by means of ridge estimation for each $\lambda$ in the grid using the training set as
|
||||
!bt
|
||||
\begin{align*}
|
||||
\hat{\beta}_{-i}(\lambda) & = ( \hat{X}_{-i, \ast}^{\top}
|
||||
\hat{X}_{-i, \ast} + \lambda \hat{I}_{pp})^{-1}
|
||||
\hat{X}_{-i, \ast}^{\top} \hat{y}_{-i}
|
||||
\end{align*}
|
||||
!et
|
||||
and the corresponding estimate of the error variance $\hat{\sigma}_{-i}^2(\lambda)$.
|
||||
|
||||
o Evaluate the prediction performance of these models on the test set by $\log\{L[y_i, \hat{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\}$. Or, by the prediction error $|y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)|$, the relative error, the error squared or the R2 score function.
|
||||
|
||||
o Repeat steps 1) to 3) such that each sample plays the role of the test set once.
|
||||
|
||||
o Average the prediction performances of the test sets at each grid point of the penalty bias/parameter
|
||||
!bt
|
||||
\begin{align*}
|
||||
\frac{1}{n} \sum_{i = 1}^n \log\{L[Y_i, \mathbf{X}_{i, \ast}; \hat{\beta}_{-i}(\lambda), \hat{\sigma}_{-i}^2(\lambda)]\}.
|
||||
\end{align*}
|
||||
!et
|
||||
The quantity above is called the *cross-validated log-likelihood*. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data.
|
||||
|
||||
o The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
|
||||
|
||||
!split
|
||||
===== Predicted Residual Error Sum of Squares =====
|
||||
!bblock
|
||||
Another approach in the LOOCV scheme is to the use the so-called Predicted Residual Error Sum of Squares (PRESS).
|
||||
|
||||
We can define the optimal penalty parameter to minimize
|
||||
!bt
|
||||
\begin{align*}
|
||||
\lambda_{\mbox{{\tiny opt}}} = \arg \min_{\lambda} \frac{1}{n} \sum_{i=1}^n [y_i - \hat{X}_{i, \ast} \hat{\beta}_{-i}(\lambda)]^2.
|
||||
\end{align*}
|
||||
!et
|
||||
|
||||
The LOOCV prediction performance can be
|
||||
expressed analytically in terms of the known quantities derived from
|
||||
the design matrix and the parameters $\beta$.
|
||||
!eblock
|
||||
|
||||
!split
|
||||
===== Bootstrap =====
|
||||
!bblock
|
||||
Bootstrapping is a nonparametric approach to statistical inference
|
||||
that substitutes computation for more traditional distributional
|
||||
assumptions and asymptotic results. Bootstrapping offers a number of
|
||||
advantages:
|
||||
o The bootstrap is quite general, although there are some cases in which it fails.
|
||||
o 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.
|
||||
o It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically.
|
||||
o It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples).
|
||||
!eblock
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user