cleaning up week 37

This commit is contained in:
Morten Hjorth-Jensen
2021-09-28 10:15:00 +02:00
parent bd7debc1ab
commit c253fedc65
63 changed files with 368 additions and 682 deletions
+3 -8
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -302,7 +297,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 17, 2021</h4></center> <!-- date -->
<center><h4>Sep 28, 2021</h4></center> <!-- date -->
<br>
<p>
@@ -326,7 +321,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs008.html">9</a></li>
<li><a href="._week37-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -325,7 +320,7 @@ Recommended Reading:
<li><a href="._week37-bs009.html">10</a></li>
<li><a href="._week37-bs010.html">11</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs002.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -303,7 +298,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs010.html">11</a></li>
<li><a href="._week37-bs011.html">12</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs003.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -323,7 +318,7 @@ $$
<li><a href="._week37-bs011.html">12</a></li>
<li><a href="._week37-bs012.html">13</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs004.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -337,7 +332,7 @@ It is a conditional probability (see below) and reads as the likelihood of a dom
<li><a href="._week37-bs012.html">13</a></li>
<li><a href="._week37-bs013.html">14</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs005.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -331,7 +326,7 @@ is equivalent to the maximization/minimization of the function itself.
<li><a href="._week37-bs013.html">14</a></li>
<li><a href="._week37-bs014.html">15</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs006.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -331,7 +326,7 @@ $$
<li><a href="._week37-bs014.html">15</a></li>
<li><a href="._week37-bs015.html">16</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs007.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -322,7 +317,7 @@ which is Bayes' theorem. It allows us to evaluate the uncertainty in in \( X \)
<li><a href="._week37-bs015.html">16</a></li>
<li><a href="._week37-bs016.html">17</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs008.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -318,7 +313,7 @@ The function \( p(X) \) on the right hand side is called the prior while the fun
<li><a href="._week37-bs016.html">17</a></li>
<li><a href="._week37-bs017.html">18</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs009.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -390,7 +385,7 @@ How can we understand this?
<li><a href="._week37-bs017.html">18</a></li>
<li><a href="._week37-bs018.html">19</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs010.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -375,7 +370,7 @@ lambdas <span style="color: #666666">=</span> np<span style="color: #666666">.</
<li><a href="._week37-bs018.html">19</a></li>
<li><a href="._week37-bs019.html">20</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs011.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -341,7 +336,7 @@ We have a model for \( p(\boldsymbol{D}\vert\boldsymbol{\beta}) \) but need one
<li><a href="._week37-bs019.html">20</a></li>
<li><a href="._week37-bs020.html">21</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs012.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -347,7 +342,7 @@ which is our Ridge cost function! Nice, isn't it?
<li><a href="._week37-bs020.html">21</a></li>
<li><a href="._week37-bs021.html">22</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs013.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -341,7 +336,7 @@ which is our Lasso cost function!
<li><a href="._week37-bs021.html">22</a></li>
<li><a href="._week37-bs022.html">23</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs014.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -323,7 +318,7 @@ and discuss how to select a given model (one of the difficult parts in machine l
<li><a href="._week37-bs022.html">23</a></li>
<li><a href="._week37-bs023.html">24</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs015.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -340,7 +335,7 @@ cross-validation and the bootstrap method.
<li><a href="._week37-bs023.html">24</a></li>
<li><a href="._week37-bs024.html">25</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs016.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -336,7 +331,7 @@ bootstrap is widely used.
<li><a href="._week37-bs024.html">25</a></li>
<li><a href="._week37-bs025.html">26</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs017.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -323,7 +318,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs025.html">26</a></li>
<li><a href="._week37-bs026.html">27</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs018.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -329,7 +324,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs026.html">27</a></li>
<li><a href="._week37-bs027.html">28</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs019.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -335,7 +330,7 @@ training error reaches a saturation.
<li><a href="._week37-bs027.html">28</a></li>
<li><a href="._week37-bs028.html">29</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs020.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -329,7 +324,7 @@ need for bootstrapping.
<li><a href="._week37-bs028.html">29</a></li>
<li><a href="._week37-bs029.html">30</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs021.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -325,7 +320,7 @@ number \( i \) is left out. Using this notation, define
<li><a href="._week37-bs029.html">30</a></li>
<li><a href="._week37-bs030.html">31</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs022.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -342,7 +337,7 @@ t <span style="color: #666666">=</span> jackknife(x, stat)
<li><a href="._week37-bs030.html">31</a></li>
<li><a href="._week37-bs031.html">32</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs023.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -334,7 +329,7 @@ Before we proceed however, we need to remind ourselves about a central theorem i
<li><a href="._week37-bs031.html">32</a></li>
<li><a href="._week37-bs032.html">33</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs024.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -328,7 +323,7 @@ the question we pose is which is the PDF of the new variable \( z \).
<li><a href="._week37-bs032.html">33</a></li>
<li><a href="._week37-bs033.html">34</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs025.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -326,7 +321,7 @@ product of individual \( p(x_i) \). The independence assumption is important in
<li><a href="._week37-bs033.html">34</a></li>
<li><a href="._week37-bs034.html">35</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs026.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -335,7 +330,7 @@ $$
<li><a href="._week37-bs034.html">35</a></li>
<li><a href="._week37-bs035.html">36</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs027.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -337,7 +332,7 @@ and \( \mu \) is also the mean of the PDF \( p(x) \).
<li><a href="._week37-bs035.html">36</a></li>
<li><a href="._week37-bs036.html">37</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs028.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -350,7 +345,7 @@ finite \( m \), it is not always possible to find a closed form /analytic expres
<li><a href="._week37-bs036.html">37</a></li>
<li><a href="._week37-bs037.html">38</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs029.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -328,7 +323,7 @@ construct a confidence interval for the estimates.
<li><a href="._week37-bs037.html">38</a></li>
<li><a href="._week37-bs038.html">39</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs030.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -336,7 +331,7 @@ Bootstrap method, why it works and various theorems related to it.
<li><a href="._week37-bs038.html">39</a></li>
<li><a href="._week37-bs039.html">40</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs031.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -322,7 +317,7 @@ estimators.
<li><a href="._week37-bs039.html">40</a></li>
<li><a href="._week37-bs040.html">41</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs032.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -328,7 +323,7 @@ idea is to use the relative frequency of \( \widehat{\beta}^* \)
<li><a href="._week37-bs040.html">41</a></li>
<li><a href="._week37-bs041.html">42</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs033.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -324,7 +319,7 @@ result in some asymptotic sense? The answer is yes.
<li><a href="._week37-bs041.html">42</a></li>
<li><a href="._week37-bs042.html">43</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs034.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -331,7 +326,7 @@ example, if you are interested in estimating the variance of \( \widehat
<li><a href="._week37-bs042.html">43</a></li>
<li><a href="._week37-bs043.html">44</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs035.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -358,7 +353,7 @@ We see that our new variance and from that the standard deviation, agrees with t
<li><a href="._week37-bs043.html">44</a></li>
<li><a href="._week37-bs044.html">45</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs036.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -323,7 +318,7 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs044.html">45</a></li>
<li><a href="._week37-bs045.html">46</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs037.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -372,7 +367,7 @@ that is the rewriting in terms of the so-called bias, the variance of the model
<li><a href="._week37-bs045.html">46</a></li>
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs038.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+2 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -314,7 +309,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs039.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -8
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -367,8 +362,6 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs040.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -358,7 +353,6 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs041.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -340,7 +335,6 @@ You may also find this recent <a href="https://www.pnas.org/content/116/32/15849
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs042.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -381,7 +376,6 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs043.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -322,7 +317,6 @@ cross-validation (LOOCV).
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs044.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -332,7 +327,6 @@ $$
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs045.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -321,7 +316,6 @@ For the various values of \( k \)
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs046.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+1 -7
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -398,7 +393,6 @@ plt<span style="color: #666666">.</span>show()
<li class="active"><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs047.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+5 -8
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -348,7 +343,7 @@ trials <span style="color: #666666">=</span> <span style="color: #666666">100</s
trainingerror[polydegree] <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
<span style="color: #008000; font-weight: bold">for</span> samples <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(trials):
x_train, x_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, Energies, test_size<span style="color: #666666">=0.2</span>)
model <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)<span style="color: #666666">.</span>fit(x_train, y_train)
model <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)<span style="color: #666666">.</span>fit(x_train, y_train)
ypred <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(x_train)
ytilde <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(x_test)
testerror[polydegree] <span style="color: #666666">+=</span> mean_squared_error(y_test, ytilde)
@@ -367,6 +362,9 @@ plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39
plt<span style="color: #666666">.</span>legend()
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
Note that we kept the intercept column in the fitting here. This means that we need to set the <b>intercept</b> in the call to the <b>Scikit-Learn</b> function as <b>False</b>. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
@@ -384,7 +382,6 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs046.html">47</a></li>
<li class="active"><a href="._week37-bs047.html">48</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+5 -9
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -285,6 +280,8 @@ MathJax.Hub.Config({
<h2 id="the-same-example-but-now-with-cross-validation" class="anchor">The same example but now with cross-validation </h2>
<p>
In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
@@ -344,7 +341,7 @@ kfold <span style="color: #666666">=</span> KFold(n_splits <span style="color: #
polynomial[polydegree] <span style="color: #666666">=</span> polydegree
<span style="color: #008000; font-weight: bold">for</span> degree <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(polydegree):
X[:,degree] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(degree<span style="color: #666666">/3.0</span>)
OLS <span style="color: #666666">=</span> LinearRegression()
OLS <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
<span style="color: #408080; font-style: italic"># loop over trials in order to estimate the expectation value of the MSE</span>
estimated_mse_folds <span style="color: #666666">=</span> cross_val_score(OLS, X, Energies, scoring<span style="color: #666666">=</span><span style="color: #BA2121">&#39;neg_mean_squared_error&#39;</span>, cv<span style="color: #666666">=</span>kfold)
<span style="color: #408080; font-style: italic">#[:, np.newaxis]</span>
@@ -357,6 +354,7 @@ 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 -->
<ul class="pagination">
@@ -372,8 +370,6 @@ plt<span style="color: #666666">.</span>show()
<li><a href="._week37-bs046.html">47</a></li>
<li><a href="._week37-bs047.html">48</a></li>
<li class="active"><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs049.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+3 -8
View File
@@ -177,11 +177,7 @@ Automatically generated HTML file from DocOnce source
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -267,7 +263,6 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._week37-bs046.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs047.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs048.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
<!-- navigation toc: --> <li><a href="._week37-bs049.html#cross-validation-with-ridge" style="font-size: 80%;">Cross-validation with Ridge</a></li>
</ul>
</li>
@@ -302,7 +297,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 17, 2021</h4></center> <!-- date -->
<center><h4>Sep 28, 2021</h4></center> <!-- date -->
<br>
<p>
@@ -326,7 +321,7 @@ MathJax.Hub.Config({
<li><a href="._week37-bs008.html">9</a></li>
<li><a href="._week37-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._week37-bs049.html">50</a></li>
<li><a href="._week37-bs048.html">49</a></li>
<li><a href="._week37-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+7 -47
View File
@@ -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>&nbsp;<br>
<center><h4>Sep 17, 2021</h4></center> <!-- date -->
<center><h4>Sep 28, 2021</h4></center> <!-- date -->
<br>
<p>
@@ -1845,7 +1845,7 @@ trials = <span style="color: #B452CD">100</span>
trainingerror[polydegree] = <span style="color: #B452CD">0.0</span>
<span style="color: #8B008B; font-weight: bold">for</span> samples <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(trials):
x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=<span style="color: #B452CD">0.2</span>)
model = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">True</span>).fit(x_train, y_train)
model = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">False</span>).fit(x_train, y_train)
ypred = model.predict(x_train)
ytilde = model.predict(x_test)
testerror[polydegree] += mean_squared_error(y_test, ytilde)
@@ -1864,12 +1864,16 @@ plt.ylabel(<span style="color: #CD5555">&#39;log10[MSE]&#39;</span>)
plt.legend()
plt.show()
</pre></div>
<p>
Note that we kept the intercept column in the fitting here. This means that we need to set the <b>intercept</b> in the call to the <b>Scikit-Learn</b> function as <b>False</b>. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.
</section>
<section>
<h2 id="the-same-example-but-now-with-cross-validation">The same example but now with cross-validation </h2>
<p>
In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
@@ -1929,7 +1933,7 @@ kfold = KFold(n_splits = k)
polynomial[polydegree] = polydegree
<span style="color: #8B008B; font-weight: bold">for</span> degree <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(polydegree):
X[:,degree] = Density**(degree/<span style="color: #B452CD">3.0</span>)
OLS = LinearRegression()
OLS = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">False</span>)
<span style="color: #228B22"># loop over trials in order to estimate the expectation value of the MSE</span>
estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring=<span style="color: #CD5555">&#39;neg_mean_squared_error&#39;</span>, cv=kfold)
<span style="color: #228B22">#[:, np.newaxis]</span>
@@ -1944,50 +1948,6 @@ plt.show()
</section>
<section>
<h2 id="cross-validation-with-ridge">Cross-validation with Ridge </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">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> KFold
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> Ridge
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> cross_val_score
<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: #228B22"># A seed just to ensure that the random numbers are the same for every run.</span>
np.random.seed(<span style="color: #B452CD">3155</span>)
<span style="color: #228B22"># Generate the data.</span>
n = <span style="color: #B452CD">100</span>
x = np.linspace(-<span style="color: #B452CD">3</span>, <span style="color: #B452CD">3</span>, n).reshape(-<span style="color: #B452CD">1</span>, <span style="color: #B452CD">1</span>)
y = np.exp(-x**<span style="color: #B452CD">2</span>) + <span style="color: #B452CD">1.5</span> * np.exp(-(x-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>)+ np.random.normal(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.1</span>, x.shape)
<span style="color: #228B22"># Decide degree on polynomial to fit</span>
poly = PolynomialFeatures(degree = <span style="color: #B452CD">10</span>)
<span style="color: #228B22"># Decide which values of lambda to use</span>
nlambdas = <span style="color: #B452CD">500</span>
lambdas = np.logspace(-<span style="color: #B452CD">3</span>, <span style="color: #B452CD">5</span>, nlambdas)
<span style="color: #228B22"># Initialize a KFold instance</span>
k = <span style="color: #B452CD">5</span>
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = <span style="color: #B452CD">0</span>
<span style="color: #8B008B; font-weight: bold">for</span> lmb <span style="color: #8B008B">in</span> lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring=<span style="color: #CD5555">&#39;neg_mean_squared_error&#39;</span>, cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += <span style="color: #B452CD">1</span>
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = <span style="color: #CD5555">&#39;cross_val_score&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;log10(lambda)&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;MSE&#39;</span>)
plt.legend()
plt.show()
</pre></div>
</section>
</div> <!-- class="slides" -->
</div> <!-- class="reveal" -->
+9 -51
View File
@@ -197,11 +197,7 @@ div { text-align: justify; text-justify: inter-word; }
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -243,7 +239,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 17, 2021</h4></center> <!-- date -->
<center><h4>Sep 28, 2021</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -1844,7 +1840,7 @@ trials = <span style="color: #B452CD">100</span>
trainingerror[polydegree] = <span style="color: #B452CD">0.0</span>
<span style="color: #8B008B; font-weight: bold">for</span> samples <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(trials):
x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=<span style="color: #B452CD">0.2</span>)
model = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">True</span>).fit(x_train, y_train)
model = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">False</span>).fit(x_train, y_train)
ypred = model.predict(x_train)
ytilde = model.predict(x_test)
testerror[polydegree] += mean_squared_error(y_test, ytilde)
@@ -1863,11 +1859,16 @@ plt.ylabel(<span style="color: #CD5555">&#39;log10[MSE]&#39;</span>)
plt.legend()
plt.show()
</pre></div>
<p>
Note that we kept the intercept column in the fitting here. This means that we need to set the <b>intercept</b> in the call to the <b>Scikit-Learn</b> function as <b>False</b>. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.
<p>
<!-- !split -->
<h2 id="the-same-example-but-now-with-cross-validation">The same example but now with cross-validation </h2>
<p>
In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
@@ -1927,7 +1928,7 @@ kfold = KFold(n_splits = k)
polynomial[polydegree] = polydegree
<span style="color: #8B008B; font-weight: bold">for</span> degree <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(polydegree):
X[:,degree] = Density**(degree/<span style="color: #B452CD">3.0</span>)
OLS = LinearRegression()
OLS = LinearRegression(fit_intercept=<span style="color: #8B008B; font-weight: bold">False</span>)
<span style="color: #228B22"># loop over trials in order to estimate the expectation value of the MSE</span>
estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring=<span style="color: #CD5555">&#39;neg_mean_squared_error&#39;</span>, cv=kfold)
<span style="color: #228B22">#[:, np.newaxis]</span>
@@ -1940,49 +1941,6 @@ plt.legend()
plt.show()
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="cross-validation-with-ridge">Cross-validation with Ridge </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">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> KFold
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> Ridge
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> cross_val_score
<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: #228B22"># A seed just to ensure that the random numbers are the same for every run.</span>
np.random.seed(<span style="color: #B452CD">3155</span>)
<span style="color: #228B22"># Generate the data.</span>
n = <span style="color: #B452CD">100</span>
x = np.linspace(-<span style="color: #B452CD">3</span>, <span style="color: #B452CD">3</span>, n).reshape(-<span style="color: #B452CD">1</span>, <span style="color: #B452CD">1</span>)
y = np.exp(-x**<span style="color: #B452CD">2</span>) + <span style="color: #B452CD">1.5</span> * np.exp(-(x-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>)+ np.random.normal(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.1</span>, x.shape)
<span style="color: #228B22"># Decide degree on polynomial to fit</span>
poly = PolynomialFeatures(degree = <span style="color: #B452CD">10</span>)
<span style="color: #228B22"># Decide which values of lambda to use</span>
nlambdas = <span style="color: #B452CD">500</span>
lambdas = np.logspace(-<span style="color: #B452CD">3</span>, <span style="color: #B452CD">5</span>, nlambdas)
<span style="color: #228B22"># Initialize a KFold instance</span>
k = <span style="color: #B452CD">5</span>
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = <span style="color: #B452CD">0</span>
<span style="color: #8B008B; font-weight: bold">for</span> lmb <span style="color: #8B008B">in</span> lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring=<span style="color: #CD5555">&#39;neg_mean_squared_error&#39;</span>, cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += <span style="color: #B452CD">1</span>
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = <span style="color: #CD5555">&#39;cross_val_score&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;log10(lambda)&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;MSE&#39;</span>)
plt.legend()
plt.show()
</pre></div>
<p>
<!-- ------------------- end of main content --------------- -->
+9 -51
View File
@@ -202,11 +202,7 @@ div { text-align: justify; text-justify: inter-word; }
('The same example but now with cross-validation',
2,
None,
'the-same-example-but-now-with-cross-validation'),
('Cross-validation with Ridge',
2,
None,
'cross-validation-with-ridge')]}
'the-same-example-but-now-with-cross-validation')]}
end of tocinfo -->
<body>
@@ -248,7 +244,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 17, 2021</h4></center> <!-- date -->
<center><h4>Sep 28, 2021</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -1849,7 +1845,7 @@ trials <span style="color: #666666">=</span> <span style="color: #666666">100</s
trainingerror[polydegree] <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
<span style="color: #008000; font-weight: bold">for</span> samples <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(trials):
x_train, x_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, Energies, test_size<span style="color: #666666">=0.2</span>)
model <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)<span style="color: #666666">.</span>fit(x_train, y_train)
model <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)<span style="color: #666666">.</span>fit(x_train, y_train)
ypred <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(x_train)
ytilde <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(x_test)
testerror[polydegree] <span style="color: #666666">+=</span> mean_squared_error(y_test, ytilde)
@@ -1868,11 +1864,16 @@ plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39
plt<span style="color: #666666">.</span>legend()
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
Note that we kept the intercept column in the fitting here. This means that we need to set the <b>intercept</b> in the call to the <b>Scikit-Learn</b> function as <b>False</b>. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.
<p>
<!-- !split -->
<h2 id="the-same-example-but-now-with-cross-validation">The same example but now with cross-validation </h2>
<p>
In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
@@ -1932,7 +1933,7 @@ kfold <span style="color: #666666">=</span> KFold(n_splits <span style="color: #
polynomial[polydegree] <span style="color: #666666">=</span> polydegree
<span style="color: #008000; font-weight: bold">for</span> degree <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(polydegree):
X[:,degree] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(degree<span style="color: #666666">/3.0</span>)
OLS <span style="color: #666666">=</span> LinearRegression()
OLS <span style="color: #666666">=</span> LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
<span style="color: #408080; font-style: italic"># loop over trials in order to estimate the expectation value of the MSE</span>
estimated_mse_folds <span style="color: #666666">=</span> cross_val_score(OLS, X, Energies, scoring<span style="color: #666666">=</span><span style="color: #BA2121">&#39;neg_mean_squared_error&#39;</span>, cv<span style="color: #666666">=</span>kfold)
<span style="color: #408080; font-style: italic">#[:, np.newaxis]</span>
@@ -1945,49 +1946,6 @@ plt<span style="color: #666666">.</span>legend()
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="cross-validation-with-ridge">Cross-validation with Ridge </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.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> KFold
<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.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> cross_val_score
<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: #408080; font-style: italic"># A seed just to ensure that the random numbers are the same for every run.</span>
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">3155</span>)
<span style="color: #408080; font-style: italic"># Generate the data.</span>
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-3</span>, <span style="color: #666666">3</span>, n)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>x<span style="color: #666666">**2</span>) <span style="color: #666666">+</span> <span style="color: #666666">1.5</span> <span style="color: #666666">*</span> np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>(x<span style="color: #666666">-2</span>)<span style="color: #666666">**2</span>)<span style="color: #666666">+</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(<span style="color: #666666">0</span>, <span style="color: #666666">0.1</span>, x<span style="color: #666666">.</span>shape)
<span style="color: #408080; font-style: italic"># Decide degree on polynomial to fit</span>
poly <span style="color: #666666">=</span> PolynomialFeatures(degree <span style="color: #666666">=</span> <span style="color: #666666">10</span>)
<span style="color: #408080; font-style: italic"># Decide which values of lambda to use</span>
nlambdas <span style="color: #666666">=</span> <span style="color: #666666">500</span>
lambdas <span style="color: #666666">=</span> np<span style="color: #666666">.</span>logspace(<span style="color: #666666">-3</span>, <span style="color: #666666">5</span>, nlambdas)
<span style="color: #408080; font-style: italic"># Initialize a KFold instance</span>
k <span style="color: #666666">=</span> <span style="color: #666666">5</span>
kfold <span style="color: #666666">=</span> KFold(n_splits <span style="color: #666666">=</span> k)
estimated_mse_sklearn <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(nlambdas)
i <span style="color: #666666">=</span> <span style="color: #666666">0</span>
<span style="color: #008000; font-weight: bold">for</span> lmb <span style="color: #AA22FF; font-weight: bold">in</span> lambdas:
ridge <span style="color: #666666">=</span> Ridge(alpha <span style="color: #666666">=</span> lmb)
estimated_mse_folds <span style="color: #666666">=</span> cross_val_score(ridge, x, y, scoring<span style="color: #666666">=</span><span style="color: #BA2121">&#39;neg_mean_squared_error&#39;</span>, cv<span style="color: #666666">=</span>kfold)
estimated_mse_sklearn[i] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean(<span style="color: #666666">-</span>estimated_mse_folds)
i <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
plt<span style="color: #666666">.</span>figure()
plt<span style="color: #666666">.</span>plot(np<span style="color: #666666">.</span>log10(lambdas), estimated_mse_sklearn, label <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;cross_val_score&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;log10(lambda)&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;MSE&#39;</span>)
plt<span style="color: #666666">.</span>legend()
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
<!-- ------------------- end of main content --------------- -->
Binary file not shown.
+8 -57
View File
@@ -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 17, 2021**\n",
"Date: **Sep 28, 2021**\n",
"\n",
"Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -1984,7 +1984,7 @@
" trainingerror[polydegree] = 0.0\n",
" for samples in range(trials):\n",
" x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2)\n",
" model = LinearRegression(fit_intercept=True).fit(x_train, y_train)\n",
" model = LinearRegression(fit_intercept=False).fit(x_train, y_train)\n",
" ypred = model.predict(x_train)\n",
" ytilde = model.predict(x_test)\n",
" testerror[polydegree] += mean_squared_error(y_test, ytilde)\n",
@@ -2008,8 +2008,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that we kept the intercept column in the fitting here. This means that we need to set the **intercept** in the call to the **Scikit-Learn** function as **False**. Alternatively, we could have set up the design matrix $X$ without the first column of ones.\n",
"\n",
"<!-- !split -->\n",
"## The same example but now with cross-validation"
"## The same example but now with cross-validation\n",
"\n",
"In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error."
]
},
{
@@ -2077,7 +2081,7 @@
" polynomial[polydegree] = polydegree\n",
" for degree in range(polydegree):\n",
" X[:,degree] = Density**(degree/3.0)\n",
" OLS = LinearRegression()\n",
" OLS = LinearRegression(fit_intercept=False)\n",
"# loop over trials in order to estimate the expectation value of the MSE\n",
" estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring='neg_mean_squared_error', cv=kfold)\n",
"#[:, np.newaxis]\n",
@@ -2089,59 +2093,6 @@
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cross-validation with Ridge"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.model_selection import KFold\n",
"from sklearn.linear_model import Ridge\n",
"from sklearn.model_selection import cross_val_score\n",
"from sklearn.preprocessing import PolynomialFeatures\n",
"\n",
"# A seed just to ensure that the random numbers are the same for every run.\n",
"np.random.seed(3155)\n",
"# Generate the data.\n",
"n = 100\n",
"x = np.linspace(-3, 3, n).reshape(-1, 1)\n",
"y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)\n",
"# Decide degree on polynomial to fit\n",
"poly = PolynomialFeatures(degree = 10)\n",
"\n",
"# Decide which values of lambda to use\n",
"nlambdas = 500\n",
"lambdas = np.logspace(-3, 5, nlambdas)\n",
"# Initialize a KFold instance\n",
"k = 5\n",
"kfold = KFold(n_splits = k)\n",
"estimated_mse_sklearn = np.zeros(nlambdas)\n",
"i = 0\n",
"for lmb in lambdas:\n",
" ridge = Ridge(alpha = lmb)\n",
" estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)\n",
" estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)\n",
" i += 1\n",
"plt.figure()\n",
"plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')\n",
"plt.xlabel('log10(lambda)')\n",
"plt.ylabel('MSE')\n",
"plt.legend()\n",
"plt.show()"
]
}
],
"metadata": {},
+4 -51
View File
@@ -1485,7 +1485,7 @@ for polydegree in range(1, Maxpolydegree):
trainingerror[polydegree] = 0.0
for samples in range(trials):
x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2)
model = LinearRegression(fit_intercept=True).fit(x_train, y_train)
model = LinearRegression(fit_intercept=False).fit(x_train, y_train)
ypred = model.predict(x_train)
ytilde = model.predict(x_test)
testerror[polydegree] += mean_squared_error(y_test, ytilde)
@@ -1506,10 +1506,12 @@ plt.show()
!ec
Note that we kept the intercept column in the fitting here. This means that we need to set the _intercept_ in the call to the _Scikit-Learn_ function as _False_. Alternatively, we could have set up the design matrix $X$ without the first column of ones.
!split
===== The same example but now with cross-validation =====
In this example we keep the intercept column again but add cross-validation in order to estimate the best possible value of the means squared error.
!bc pycod
# Common imports
import os
@@ -1567,7 +1569,7 @@ for polydegree in range(1, Maxpolydegree):
polynomial[polydegree] = polydegree
for degree in range(polydegree):
X[:,degree] = Density**(degree/3.0)
OLS = LinearRegression()
OLS = LinearRegression(fit_intercept=False)
# loop over trials in order to estimate the expectation value of the MSE
estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring='neg_mean_squared_error', cv=kfold)
#[:, np.newaxis]
@@ -1581,52 +1583,3 @@ plt.show()
!ec
!split
===== Cross-validation with Ridge =====
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import PolynomialFeatures
# A seed just to ensure that the random numbers are the same for every run.
np.random.seed(3155)
# Generate the data.
n = 100
x = np.linspace(-3, 3, n).reshape(-1, 1)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
# Decide degree on polynomial to fit
poly = PolynomialFeatures(degree = 10)
# Decide which values of lambda to use
nlambdas = 500
lambdas = np.logspace(-3, 5, nlambdas)
# Initialize a KFold instance
k = 5
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = 0
for lmb in lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += 1
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
plt.xlabel('log10(lambda)')
plt.ylabel('MSE')
plt.legend()
plt.show()
!ec
+16
View File
@@ -0,0 +1,16 @@
import numpy as np
from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.model_selection import GridSearchCV
# load the diabetes datasets
dataset = datasets.load_diabetes()
# prepare a range of alpha values to test
alphas = np.array([1,0.1,0.01,0.001,0.0001,0])
# create and fit a ridge regression model, testing each alpha
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=alphas))
grid.fit(dataset.data, dataset.target)
print(grid)
# summarize the results of the grid search
print(grid.best_score_)
print(grid.best_estimator_.alpha)
+17
View File
@@ -0,0 +1,17 @@
import numpy as np
from scipy.stats import uniform as sp_rand
from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.model_selection import RandomizedSearchCV
# load the diabetes datasets
dataset = datasets.load_diabetes()
# prepare a uniform distribution to sample for the alpha parameter
param_grid = {'alpha': sp_rand()}
# create and fit a ridge regression model, testing random alpha values
model = Ridge()
rsearch = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
rsearch.fit(dataset.data, dataset.target)
print(rsearch)
# summarize the results of the random parameter search
print(rsearch.best_score_)
print(rsearch.best_estimator_.alpha)
+30
View File
@@ -0,0 +1,30 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import PolynomialFeatures
from sklearn.model_selection import GridSearchCV
# A seed just to ensure that the random numbers are the same for every run.
np.random.seed(3155)
# Generate the data.
n = 100
x = np.linspace(-3, 3, n).reshape(-1, 1)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
# Decide degree on polynomial to fit
poly = PolynomialFeatures(degree = 10)
# Decide which values of lambda to use
nlambdas = 10
lambdas = np.logspace(-3, 3, nlambdas)
# create and fit a ridge regression model, testing each alpha
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
grid.fit(x, y)
print(grid)
# summarize the results of the grid search
print(grid.best_score_)
print(grid.best_estimator_.alpha)
+35
View File
@@ -0,0 +1,35 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import PolynomialFeatures
# A seed just to ensure that the random numbers are the same for every run.
np.random.seed(3155)
# Generate the data.
n = 100
x = np.linspace(-3, 3, n).reshape(-1, 1)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
# Decide degree on polynomial to fit
#poly = PolynomialFeatures(degree = 10)
# Decide which values of lambda to use
nlambdas = 500
lambdas = np.logspace(-3, 5, nlambdas)
# Initialize a KFold instance
k = 5
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = 0
for lmb in lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += 1
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
plt.xlabel('log10(lambda)')
plt.ylabel('MSE')
plt.legend()
plt.show()
+61
View File
@@ -0,0 +1,61 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Ridge
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
def MSE(y_data,y_model):
n = np.size(y_model)
return np.sum((y_data-y_model)**2)/n
# A seed just to ensure that the random numbers are the same for every run.
# Useful for eventual debugging.
np.random.seed(315)
n = 100
x = np.random.rand(n)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)
Maxpolydegree = 5
X = np.zeros((n,Maxpolydegree-1))
for degree in range(1,Maxpolydegree): #No intercept column
X[:,degree-1] = x**(degree)
# We split the data in test and training data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
#For our own implementation, we will need to deal with the intercept by centering the design matrix and the target variable
X_train_mean = np.mean(X_train,axis=0)
#Center by removing mean from each feature
X_train_scaled = X_train - X_train_mean
X_test_scaled = X_test - X_train_mean
#The model intercept (called y_scaler) is given by the mean of the target variable (IF X is centered)
#Remove the intercept from the training data.
y_scaler = np.mean(y_train)
y_train_scaled = y_train - y_scaler
p = Maxpolydegree-1
I = np.eye(p,p)
# Decide which values of lambda to use
nlambdas = 10
MSEOwnRidgePredict = np.zeros(nlambdas)
MSERidgePredict = np.zeros(nlambdas)
lambdas = np.logspace(-4, 2, nlambdas)
# create and fit a ridge regression model, testing each alpha
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
grid.fit(X_train_scaled, y_train_scaled)
print(grid)
ypredictRidge = grid.predict(X_test_scaled)
# summarize the results of the grid search
print(grid.best_score_)
print(grid.best_estimator_.alpha)
print(MSE(y_test,ypredictRidge))
+72
View File
@@ -0,0 +1,72 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Ridge
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
from scipy.stats import uniform as sp_rand
from sklearn.model_selection import RandomizedSearchCV
def R2(y_data, y_model):
return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
def MSE(y_data,y_model):
n = np.size(y_model)
return np.sum((y_data-y_model)**2)/n
# A seed just to ensure that the random numbers are the same for every run.
# Useful for eventual debugging.
np.random.seed(315)
n = 100
x = np.random.rand(n)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)
Maxpolydegree = 5
X = np.zeros((n,Maxpolydegree-1))
for degree in range(1,Maxpolydegree): #No intercept column
X[:,degree-1] = x**(degree)
# We split the data in test and training data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
#For our own implementation, we will need to deal with the intercept by centering the design matrix and the target variable
X_train_mean = np.mean(X_train,axis=0)
#Center by removing mean from each feature
X_train_scaled = X_train - X_train_mean
X_test_scaled = X_test - X_train_mean
#The model intercept (called y_scaler) is given by the mean of the target variable (IF X is centered)
#Remove the intercept from the training data.
y_scaler = np.mean(y_train)
y_train_scaled = y_train - y_scaler
y_test_scaled = y_test - y_scaler
p = Maxpolydegree-1
I = np.eye(p,p)
# Decide which values of lambda to use
nlambdas = 10
MSEOwnRidgePredict = np.zeros(nlambdas)
MSERidgePredict = np.zeros(nlambdas)
param_grid = {'alpha': sp_rand()}
# create and fit a ridge regression model, testing each alpha
model = Ridge()
grid = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_iter=100)
#GridSearchCV(estimator=model, param_grid=dict(alpha=lambdas))
grid.fit(X_train_scaled, y_train_scaled)
print(grid)
ypredictRidge = grid.predict(X_test_scaled)
# summarize the results of the grid search
print(grid.best_score_)
print(grid.best_estimator_.alpha)
print(MSE(y_test_scaled,ypredictRidge))
print(R2(y_test_scaled,ypredictRidge))
-69
View File
@@ -31,41 +31,6 @@ in evaluating the MSE as function of different $\lambda$ values.
Based on these calculations, one tries then to determine the value of the hyperparameter $\lambda$
which results in optimal scores (for example the smallest MSE or an $R2=1$).
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import PolynomialFeatures
# A seed just to ensure that the random numbers are the same for every run.
np.random.seed(3155)
# Generate the data.
n = 100
x = np.linspace(-3, 3, n).reshape(-1, 1)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
# Decide degree on polynomial to fit
poly = PolynomialFeatures(degree = 10)
# Decide which values of lambda to use
nlambdas = 500
lambdas = np.logspace(-3, 5, nlambdas)
# Initialize a KFold instance
k = 5
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = 0
for lmb in lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += 1
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
plt.xlabel('log10(lambda)')
plt.ylabel('MSE')
plt.legend()
plt.show()
!ec
We see from this plot that the optimal MSE occurs for a value of $\lambda\in [10,100]$.
@@ -80,41 +45,7 @@ included with the library _Scikit-Learn_, as demonstrated for the same
example here.
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import PolynomialFeatures
# A seed just to ensure that the random numbers are the same for every run.
np.random.seed(3155)
# Generate the data.
n = 100
x = np.linspace(-3, 3, n).reshape(-1, 1)
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
# Decide degree on polynomial to fit
poly = PolynomialFeatures(degree = 10)
# Decide which values of lambda to use
nlambdas = 500
lambdas = np.logspace(-3, 5, nlambdas)
# Initialize a KFold instance
k = 5
kfold = KFold(n_splits = k)
estimated_mse_sklearn = np.zeros(nlambdas)
i = 0
for lmb in lambdas:
ridge = Ridge(alpha = lmb)
estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold)
estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
i += 1
plt.figure()
plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
plt.xlabel('log10(lambda)')
plt.ylabel('MSE')
plt.legend()
plt.show()
!ec