update week 45
This commit is contained in:
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -195,7 +199,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 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 31, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -219,7 +223,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week45-bs008.html">9</a></li>
|
||||
<li><a href="._week45-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,46 +180,14 @@ MathJax.Hub.Config({
|
||||
<a name="part0001"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec0" class="anchor">Random forests </h2>
|
||||
<h2 id="___sec0" class="anchor">Overview of week 45 </h2>
|
||||
|
||||
<p>
|
||||
Random forests provide an improvement over bagged trees by way of a
|
||||
small tweak that decorrelates the trees.
|
||||
<ul>
|
||||
<li> "Thursday: Wrapping up from last week. Bagging and Random forests.</li>
|
||||
<li> "Friday: Boosting and gradient boosting</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
As in bagging, we build a
|
||||
number of decision trees on bootstrapped training samples. But when
|
||||
building these decision trees, each time a split in a tree is
|
||||
considered, a random sample of \( m \) predictors is chosen as split
|
||||
candidates from the full set of \( p \) predictors. The split is allowed to
|
||||
use only one of those \( m \) predictors.
|
||||
|
||||
<p>
|
||||
A fresh sample of \( m \) predictors is
|
||||
taken at each split, and typically we choose
|
||||
|
||||
$$
|
||||
m\approx \sqrt{p}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In building a random forest, at
|
||||
each split in the tree, the algorithm is not even allowed to consider
|
||||
a majority of the available predictors.
|
||||
|
||||
<p>
|
||||
The reason for this is rather clever. Suppose that there is one very
|
||||
strong predictor in the data set, along with a number of other
|
||||
moderately strong predictors. Then in the collection of bagged
|
||||
variable importance random forest trees, most or all of the trees will
|
||||
use this strong predictor in the top split. Consequently, all of the
|
||||
bagged trees will look quite similar to each other. Hence the
|
||||
predictions from the bagged trees will be highly correlated.
|
||||
Unfortunately, averaging many highly correlated quantities does not
|
||||
lead to as large of a reduction in variance as averaging many
|
||||
uncorrelated quantities. In particular, this means that bagging will
|
||||
not lead to a substantial reduction in variance over a single tree in
|
||||
this setting.
|
||||
Geron's chapter 7. See also lecture from <a href="https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf" target="_self">STK-IN4300, lecture 7</a>. Chapter 9.2 of Hastie et al contains also a good discussion.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -234,7 +206,7 @@ this setting.
|
||||
<li><a href="._week45-bs009.html">10</a></li>
|
||||
<li><a href="._week45-bs010.html">11</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,30 +180,12 @@ MathJax.Hub.Config({
|
||||
<a name="part0002"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec1" class="anchor">Random Forest Algorithm </h2>
|
||||
The algorithm described here can be applied to both classification and regression problems.
|
||||
<h2 id="___sec1" class="anchor">Thursday </h2>
|
||||
|
||||
<p>
|
||||
We will grow of forest of say \( B \) trees.
|
||||
|
||||
<ol>
|
||||
<li> For \( b=1:B \)</li>
|
||||
|
||||
<ul>
|
||||
<li> Draw a bootstrap sample of from the training data organized in our \( \boldsymbol{X} \) matrix.</li>
|
||||
<li> We grow then a random forest tree \( T_b \) based on the bootstrapped data by repeating the steps outlined till we reach the maximum node size is reached</li>
|
||||
|
||||
<ol>
|
||||
<li> we select \( m \le p \) variables at random from the \( p \) predictors/features</li>
|
||||
<li> pick the best split point among the \( m \) features using either the CART algorithm or the ID3 for classification and create a new node</li>
|
||||
<li> split the node into daughter nodes</li>
|
||||
</ol>
|
||||
|
||||
</ul>
|
||||
|
||||
<li> Output then the ensemble of trees \( \{T_b\}_1^{B} \) and make predictions for either a regression type of problem or a classification type of problem.</li>
|
||||
</ol>
|
||||
Bagging, voting and random forests.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -217,7 +203,7 @@ We will grow of forest of say \( B \) trees.
|
||||
<li><a href="._week45-bs010.html">11</a></li>
|
||||
<li><a href="._week45-bs011.html">12</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs003.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,76 +180,47 @@ MathJax.Hub.Config({
|
||||
<a name="part0003"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec2" class="anchor">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<h2 id="___sec2" class="anchor">Random forests </h2>
|
||||
|
||||
<p>
|
||||
Random forests provide an improvement over bagged trees by way of a
|
||||
small tweak that decorrelates the trees.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.datasets</span> <span style="color: #008000; font-weight: bold">import</span> load_breast_cancer
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.svm</span> <span style="color: #008000; font-weight: bold">import</span> SVC
|
||||
<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> LogisticRegression
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<p>
|
||||
As in bagging, we build a
|
||||
number of decision trees on bootstrapped training samples. But when
|
||||
building these decision trees, each time a split in a tree is
|
||||
considered, a random sample of \( m \) predictors is chosen as split
|
||||
candidates from the full set of \( p \) predictors. The split is allowed to
|
||||
use only one of those \( m \) predictors.
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
<p>
|
||||
A fresh sample of \( m \) predictors is
|
||||
taken at each split, and typically we choose
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">'lbfgs'</span>)
|
||||
logreg<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Logistic Regression: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support vector machine</span>
|
||||
svm <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">'auto'</span>, C<span style="color: #666666">=100</span>)
|
||||
svm<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with SVM: {:.2f}"</span><span style="color: #666666">.</span>format(svm<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=</span><span style="color: #008000">None</span>)
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees: {:.2f}"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support Vector Machine</span>
|
||||
svm<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy SVM with scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
$$
|
||||
m\approx \sqrt{p}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In building a random forest, at
|
||||
each split in the tree, the algorithm is not even allowed to consider
|
||||
a majority of the available predictors.
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
|
||||
<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> LabelEncoder
|
||||
<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_validate
|
||||
<span style="color: #408080; font-style: italic"># Data set not specificied</span>
|
||||
<span style="color: #408080; font-style: italic">#Instantiate the model with 500 trees and entropy as splitting criteria</span>
|
||||
Random_Forest_model <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=500</span>,criterion<span style="color: #666666">=</span><span style="color: #BA2121">"entropy"</span>)
|
||||
Random_Forest_model<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(Random_Forest_model,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(Random_Forest_model<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<p>
|
||||
The reason for this is rather clever. Suppose that there is one very
|
||||
strong predictor in the data set, along with a number of other
|
||||
moderately strong predictors. Then in the collection of bagged
|
||||
variable importance random forest trees, most or all of the trees will
|
||||
use this strong predictor in the top split. Consequently, all of the
|
||||
bagged trees will look quite similar to each other. Hence the
|
||||
predictions from the bagged trees will be highly correlated.
|
||||
Unfortunately, averaging many highly correlated quantities does not
|
||||
lead to as large of a reduction in variance as averaging many
|
||||
uncorrelated quantities. In particular, this means that bagging will
|
||||
not lead to a substantial reduction in variance over a single tree in
|
||||
this setting.
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -265,7 +240,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs011.html">12</a></li>
|
||||
<li><a href="._week45-bs012.html">13</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs004.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,26 +180,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0004"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec3" class="anchor">Compare Bagging on Trees with Random Forests </h2>
|
||||
<p>
|
||||
<h2 id="___sec3" class="anchor">Random Forest Algorithm </h2>
|
||||
The algorithm described here can be applied to both classification and regression problems.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf <span style="color: #666666">=</span> BaggingClassifier(
|
||||
DecisionTreeClassifier(splitter<span style="color: #666666">=</span><span style="color: #BA2121">"random"</span>, max_leaf_nodes<span style="color: #666666">=16</span>, random_state<span style="color: #666666">=42</span>),
|
||||
n_estimators<span style="color: #666666">=500</span>, max_samples<span style="color: #666666">=1.0</span>, bootstrap<span style="color: #666666">=</span><span style="color: #008000">True</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
We will grow of forest of say \( B \) trees.
|
||||
|
||||
<ol>
|
||||
<li> For \( b=1:B \)</li>
|
||||
|
||||
<ul>
|
||||
<li> Draw a bootstrap sample of from the training data organized in our \( \boldsymbol{X} \) matrix.</li>
|
||||
<li> We grow then a random forest tree \( T_b \) based on the bootstrapped data by repeating the steps outlined till we reach the maximum node size is reached</li>
|
||||
|
||||
<ol>
|
||||
<li> we select \( m \le p \) variables at random from the \( p \) predictors/features</li>
|
||||
<li> pick the best split point among the \( m \) features using either the CART algorithm or the ID3 for classification and create a new node</li>
|
||||
<li> split the node into daughter nodes</li>
|
||||
</ol>
|
||||
|
||||
</ul>
|
||||
|
||||
<li> Output then the ensemble of trees \( \{T_b\}_1^{B} \) and make predictions for either a regression type of problem or a classification type of problem.</li>
|
||||
</ol>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> bag_clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=500</span>, max_leaf_nodes<span style="color: #666666">=16</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred_rf <span style="color: #666666">=</span> rnd_clf<span style="color: #666666">.</span>predict(X_test)
|
||||
np<span style="color: #666666">.</span>sum(y_pred <span style="color: #666666">==</span> y_pred_rf) <span style="color: #666666">/</span> <span style="color: #008000">len</span>(y_pred)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -215,7 +223,7 @@ np<span style="color: #666666">.</span>sum(y_pred <span style="color: #666666">=
|
||||
<li><a href="._week45-bs012.html">13</a></li>
|
||||
<li><a href="._week45-bs013.html">14</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs005.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,20 +180,76 @@ MathJax.Hub.Config({
|
||||
<a name="part0005"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec4" class="anchor">Boosting, a Bird's Eye View </h2>
|
||||
|
||||
<h2 id="___sec4" class="anchor">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<p>
|
||||
The basic idea is to combine weak classifiers in order to create a good
|
||||
classifier. With a weak classifier we often intend a classifier which
|
||||
produces results which are only slightly better than we would get by
|
||||
random guesses.
|
||||
|
||||
<p>
|
||||
This is done by applying in an iterative way a weak (or a standard
|
||||
classifier like decision trees) to modify the data. In each iteration
|
||||
we emphasize those observations which are misclassified by weighting
|
||||
them with a factor.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.datasets</span> <span style="color: #008000; font-weight: bold">import</span> load_breast_cancer
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.svm</span> <span style="color: #008000; font-weight: bold">import</span> SVC
|
||||
<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> LogisticRegression
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">'lbfgs'</span>)
|
||||
logreg<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Logistic Regression: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support vector machine</span>
|
||||
svm <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">'auto'</span>, C<span style="color: #666666">=100</span>)
|
||||
svm<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with SVM: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(svm<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">None</span>)
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy Logistic Regression with scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support Vector Machine</span>
|
||||
svm<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy SVM with scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
|
||||
<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> LabelEncoder
|
||||
<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_validate
|
||||
<span style="color: #408080; font-style: italic"># Data set not specificied</span>
|
||||
<span style="color: #408080; font-style: italic">#Instantiate the model with 500 trees and entropy as splitting criteria</span>
|
||||
Random_Forest_model <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=500</span>,criterion<span style="color: #666666">=</span><span style="color: #BA2121">"entropy"</span>)
|
||||
Random_Forest_model<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(Random_Forest_model,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000">print</span>(accuracy)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(Random_Forest_model<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -211,7 +271,7 @@ them with a factor.
|
||||
<li><a href="._week45-bs013.html">14</a></li>
|
||||
<li><a href="._week45-bs014.html">15</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs006.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,55 +180,25 @@ MathJax.Hub.Config({
|
||||
<a name="part0006"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec5" class="anchor">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
|
||||
<h2 id="___sec5" class="anchor">Compare Bagging on Trees with Random Forests </h2>
|
||||
<p>
|
||||
Boosting is a way of fitting an additive expansion in a set of
|
||||
elementary basis functions like for example some simple polynomials.
|
||||
Assume for example that we have a function
|
||||
$$
|
||||
f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m),
|
||||
$$
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf <span style="color: #666666">=</span> BaggingClassifier(
|
||||
DecisionTreeClassifier(splitter<span style="color: #666666">=</span><span style="color: #BA2121">"random"</span>, max_leaf_nodes<span style="color: #666666">=16</span>, random_state<span style="color: #666666">=42</span>),
|
||||
n_estimators<span style="color: #666666">=500</span>, max_samples<span style="color: #666666">=1.0</span>, bootstrap<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
where \( \beta_m \) are the expansion parameters to be determined in a
|
||||
minimization process and \( b(x;\gamma_m) \) are some simple functions of
|
||||
the multivariable parameter \( x \) which is characterized by the
|
||||
parameters \( \gamma_m \).
|
||||
|
||||
<p>
|
||||
As an example, consider the Sigmoid function we used in logistic
|
||||
regression. In that case, we can translate the function
|
||||
\( b(x;\gamma_m) \) into the Sigmoid function
|
||||
|
||||
$$
|
||||
\sigma(t) = \frac{1}{1+\exp{(-t)}},
|
||||
$$
|
||||
|
||||
<p>
|
||||
where \( t=\gamma_0+\gamma_1 x \) and the parameters \( \gamma_0 \) and
|
||||
\( \gamma_1 \) were determined by the Logistic Regression fitting
|
||||
algorithm.
|
||||
|
||||
<p>
|
||||
As another example, consider the cost function we defined for linear regression
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In this case the function \( f(x) \) was replaced by the design matrix
|
||||
\( \boldsymbol{X} \) and the unknown linear regression parameters \( \boldsymbol{\beta} \),
|
||||
that is \( \boldsymbol{f}=\boldsymbol{X}\boldsymbol{\beta} \). In linear regression we can
|
||||
simply invert a matrix and obtain the parameters \( \beta \) by
|
||||
|
||||
$$
|
||||
\boldsymbol{\beta}=\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In iterative fitting or additive modeling, we minimize the cost function with respect to the parameters \( \beta_m \) and \( \gamma_m \).
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> bag_clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=500</span>, max_leaf_nodes<span style="color: #666666">=16</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred_rf <span style="color: #666666">=</span> rnd_clf<span style="color: #666666">.</span>predict(X_test)
|
||||
np<span style="color: #666666">.</span>sum(y_pred <span style="color: #666666">==</span> y_pred_rf) <span style="color: #666666">/</span> <span style="color: #008000">len</span>(y_pred)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -247,7 +221,7 @@ In iterative fitting or additive modeling, we minimize the cost function with re
|
||||
<li><a href="._week45-bs014.html">15</a></li>
|
||||
<li><a href="._week45-bs015.html">16</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs007.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,27 +180,19 @@ MathJax.Hub.Config({
|
||||
<a name="part0007"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec6" class="anchor">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
<h2 id="___sec6" class="anchor">Boosting, a Bird's Eye View </h2>
|
||||
|
||||
<p>
|
||||
The way we proceed is as follows (here we specialize to the squared-error cost function)
|
||||
The basic idea is to combine weak classifiers in order to create a good
|
||||
classifier. With a weak classifier we often intend a classifier which
|
||||
produces results which are only slightly better than we would get by
|
||||
random guesses.
|
||||
|
||||
<ol>
|
||||
<li> Establish a cost function, here \( {\cal C}(\boldsymbol{y},\boldsymbol{f}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-f_M(x_i))^2 \) with \( f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m) \).</li>
|
||||
<li> Initialize with a guess \( f_0(x) \). It could be one or even zero or some random numbers.</li>
|
||||
<li> For \( m=1:M \)
|
||||
|
||||
<ol type="a"></li>
|
||||
<li> minimize \( \sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta b(x;\gamma))^2 \) wrt \( \gamma \) and \( \beta \)</li>
|
||||
<li> This gives the optimal values \( \beta_m \) and \( \gamma_m \)</li>
|
||||
<li> Determine then the new values \( f_m(x)=f_{m-1}(x) +\beta_m b(x;\gamma_m) \)</li>
|
||||
</ol>
|
||||
|
||||
</ol>
|
||||
|
||||
We could use any of the algorithms we have discussed till now. If we
|
||||
use trees, \( \gamma \) parameterizes the split variables and split points
|
||||
at the internal nodes, and the predictions at the terminal nodes.
|
||||
<p>
|
||||
This is done by applying in an iterative way a weak (or a standard
|
||||
classifier like decision trees) to modify the data. In each iteration
|
||||
we emphasize those observations which are misclassified by weighting
|
||||
them with a factor.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -221,7 +217,7 @@ at the internal nodes, and the predictions at the terminal nodes.
|
||||
<li><a href="._week45-bs015.html">16</a></li>
|
||||
<li><a href="._week45-bs016.html">17</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs008.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,50 +180,54 @@ MathJax.Hub.Config({
|
||||
<a name="part0008"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec7" class="anchor">Squared-Error Example and Iterative Fitting </h2>
|
||||
<h2 id="___sec7" class="anchor">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.
|
||||
|
||||
<p>
|
||||
For simplicity we assume also that our functions \( b(x;\gamma)=1+\gamma x \).
|
||||
|
||||
<p>
|
||||
This means that for every iteration \( m \), we need to optimize
|
||||
|
||||
Boosting is a way of fitting an additive expansion in a set of
|
||||
elementary basis functions like for example some simple polynomials.
|
||||
Assume for example that we have a function
|
||||
$$
|
||||
(\beta_m,\gamma_m) = \mathrm{argmin}_{\beta,\lambda}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta b(x;\gamma))^2=\sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta(1+\gamma x_i))^2.
|
||||
f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m),
|
||||
$$
|
||||
|
||||
<p>
|
||||
We start our iteration by simply setting \( f_0(x)=0 \).
|
||||
Taking the derivatives with respect to \( \beta \) and \( \gamma \) we obtain
|
||||
$$
|
||||
\frac{\partial {\cal C}}{\partial \beta} = -2\sum_{i}(1+\gamma x_i)(y_i-\beta(1+\gamma x_i))=0,
|
||||
$$
|
||||
where \( \beta_m \) are the expansion parameters to be determined in a
|
||||
minimization process and \( b(x;\gamma_m) \) are some simple functions of
|
||||
the multivariable parameter \( x \) which is characterized by the
|
||||
parameters \( \gamma_m \).
|
||||
|
||||
and
|
||||
$$
|
||||
\frac{\partial {\cal C}}{\partial \gamma} =-2\sum_{i}\beta x_i(y_i-\beta(1+\gamma x_i))=0.
|
||||
$$
|
||||
<p>
|
||||
As an example, consider the Sigmoid function we used in logistic
|
||||
regression. In that case, we can translate the function
|
||||
\( b(x;\gamma_m) \) into the Sigmoid function
|
||||
|
||||
We can then rewrite these equations as (defining \( \boldsymbol{w}=\boldsymbol{e}+\gamma \boldsymbol{x}) \) with \( \boldsymbol{e} \) being the unit vector)
|
||||
$$
|
||||
\gamma \boldsymbol{w}^T(\boldsymbol{y}-\beta\gamma \boldsymbol{w})=0,
|
||||
$$
|
||||
|
||||
which gives us \( \beta = \boldsymbol{w}^T\boldsymbol{y}/(\boldsymbol{w}^T\boldsymbol{w}) \). Similarly we have
|
||||
$$
|
||||
\beta\gamma \boldsymbol{x}^T(\boldsymbol{y}-\beta(1+\gamma \boldsymbol{x}))=0,
|
||||
\sigma(t) = \frac{1}{1+\exp{(-t)}},
|
||||
$$
|
||||
|
||||
<p>
|
||||
which leads to \( \gamma =(\boldsymbol{x}^T\boldsymbol{y}-\beta\boldsymbol{x}^T\boldsymbol{e})/(\beta\boldsymbol{x}^T\boldsymbol{x}) \). Inserting
|
||||
for \( \beta \) gives us an equation for \( \gamma \). This is a non-linear equation in the unknown \( \gamma \) and has to be solved numerically.
|
||||
where \( t=\gamma_0+\gamma_1 x \) and the parameters \( \gamma_0 \) and
|
||||
\( \gamma_1 \) were determined by the Logistic Regression fitting
|
||||
algorithm.
|
||||
|
||||
<p>
|
||||
The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma_1 \) leading to the new expression for \( f_1(x) \) as
|
||||
\( f_1(x) = \beta_1(1+\gamma_1x) \). Doing this \( M \) times results in our final estimate for the function \( f \).
|
||||
As another example, consider the cost function we defined for linear regression
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In this case the function \( f(x) \) was replaced by the design matrix
|
||||
\( \boldsymbol{X} \) and the unknown linear regression parameters \( \boldsymbol{\beta} \),
|
||||
that is \( \boldsymbol{f}=\boldsymbol{X}\boldsymbol{\beta} \). In linear regression we can
|
||||
simply invert a matrix and obtain the parameters \( \beta \) by
|
||||
|
||||
$$
|
||||
\boldsymbol{\beta}=\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
In iterative fitting or additive modeling, we minimize the cost function with respect to the parameters \( \beta_m \) and \( \gamma_m \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -245,7 +253,7 @@ The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma
|
||||
<li><a href="._week45-bs016.html">17</a></li>
|
||||
<li><a href="._week45-bs017.html">18</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs009.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,37 +180,27 @@ MathJax.Hub.Config({
|
||||
<a name="part0009"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec8" class="anchor">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
<h2 id="___sec8" class="anchor">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
|
||||
<p>
|
||||
Let us consider a binary classification problem with two outcomes \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
observations. We define a classification function \( G(x) \) which produces a prediction taking one or the other of the two values
|
||||
\( \{-1,1\} \).
|
||||
The way we proceed is as follows (here we specialize to the squared-error cost function)
|
||||
|
||||
<p>
|
||||
The error rate of the training sample is then
|
||||
<ol>
|
||||
<li> Establish a cost function, here \( {\cal C}(\boldsymbol{y},\boldsymbol{f}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-f_M(x_i))^2 \) with \( f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m) \).</li>
|
||||
<li> Initialize with a guess \( f_0(x) \). It could be one or even zero or some random numbers.</li>
|
||||
<li> For \( m=1:M \)
|
||||
|
||||
$$
|
||||
\mathrm{\overline{err}}=\frac{1}{n} \sum_{i=0}^{n-1} I(y_i\ne G(x_i)).
|
||||
$$
|
||||
<ol type="a"></li>
|
||||
<li> minimize \( \sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta b(x;\gamma))^2 \) wrt \( \gamma \) and \( \beta \)</li>
|
||||
<li> This gives the optimal values \( \beta_m \) and \( \gamma_m \)</li>
|
||||
<li> Determine then the new values \( f_m(x)=f_{m-1}(x) +\beta_m b(x;\gamma_m) \)</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
The iterative procedure starts with defining a weak classifier whose
|
||||
error rate is barely better than random guessing. The iterative
|
||||
procedure in boosting is to sequentially apply a weak
|
||||
classification algorithm to repeatedly modified versions of the data
|
||||
producing a sequence of weak classifiers \( G_m(x) \).
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
Here we will express our function \( f(x) \) in terms of \( G(x) \). That is
|
||||
$$
|
||||
f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m),
|
||||
$$
|
||||
|
||||
will be a function of
|
||||
$$
|
||||
G_M(x) = \mathrm{sign} \sum_{i=1}^M \alpha_m G_m(x).
|
||||
$$
|
||||
We could use any of the algorithms we have discussed till now. If we
|
||||
use trees, \( \gamma \) parameterizes the split variables and split points
|
||||
at the internal nodes, and the predictions at the terminal nodes.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -233,7 +227,7 @@ $$
|
||||
<li><a href="._week45-bs017.html">18</a></li>
|
||||
<li><a href="._week45-bs018.html">19</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs010.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,30 +180,50 @@ MathJax.Hub.Config({
|
||||
<a name="part0010"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec9" class="anchor">Adaptive Boosting, AdaBoost </h2>
|
||||
<h2 id="___sec9" class="anchor">Squared-Error Example and Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
In our iterative procedure we define thus
|
||||
To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.
|
||||
|
||||
<p>
|
||||
For simplicity we assume also that our functions \( b(x;\gamma)=1+\gamma x \).
|
||||
|
||||
<p>
|
||||
This means that for every iteration \( m \), we need to optimize
|
||||
|
||||
$$
|
||||
f_m(x) = f_{m-1}(x)+\beta_mG_m(x).
|
||||
(\beta_m,\gamma_m) = \mathrm{argmin}_{\beta,\lambda}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta b(x;\gamma))^2=\sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\beta(1+\gamma x_i))^2.
|
||||
$$
|
||||
|
||||
<p>
|
||||
The simplest possible cost function which leads (also simple from a computational point of view) to the AdaBoost algorithm is the
|
||||
exponential cost/loss function defined as
|
||||
We start our iteration by simply setting \( f_0(x)=0 \).
|
||||
Taking the derivatives with respect to \( \beta \) and \( \gamma \) we obtain
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \sum_{i=0}^{n-1}\exp{(-y_i(f_{m-1}(x_i)+\beta G(x_i))}.
|
||||
\frac{\partial {\cal C}}{\partial \beta} = -2\sum_{i}(1+\gamma x_i)(y_i-\beta(1+\gamma x_i))=0,
|
||||
$$
|
||||
|
||||
and
|
||||
$$
|
||||
\frac{\partial {\cal C}}{\partial \gamma} =-2\sum_{i}\beta x_i(y_i-\beta(1+\gamma x_i))=0.
|
||||
$$
|
||||
|
||||
We can then rewrite these equations as (defining \( \boldsymbol{w}=\boldsymbol{e}+\gamma \boldsymbol{x}) \) with \( \boldsymbol{e} \) being the unit vector)
|
||||
$$
|
||||
\gamma \boldsymbol{w}^T(\boldsymbol{y}-\beta\gamma \boldsymbol{w})=0,
|
||||
$$
|
||||
|
||||
which gives us \( \beta = \boldsymbol{w}^T\boldsymbol{y}/(\boldsymbol{w}^T\boldsymbol{w}) \). Similarly we have
|
||||
$$
|
||||
\beta\gamma \boldsymbol{x}^T(\boldsymbol{y}-\beta(1+\gamma \boldsymbol{x}))=0,
|
||||
$$
|
||||
|
||||
<p>
|
||||
We optimize \( \beta \) and \( G \) for each value of \( m=1:M \) as we did in the regression case.
|
||||
This is normally done in two steps. Let us however first rewrite the cost function as
|
||||
which leads to \( \gamma =(\boldsymbol{x}^T\boldsymbol{y}-\beta\boldsymbol{x}^T\boldsymbol{e})/(\beta\boldsymbol{x}^T\boldsymbol{x}) \). Inserting
|
||||
for \( \beta \) gives us an equation for \( \gamma \). This is a non-linear equation in the unknown \( \gamma \) and has to be solved numerically.
|
||||
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \sum_{i=0}^{n-1}w_i^{m}\exp{(-y_i\beta G(x_i))},
|
||||
$$
|
||||
|
||||
where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
<p>
|
||||
The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma_1 \) leading to the new expression for \( f_1(x) \) as
|
||||
\( f_1(x) = \beta_1(1+\gamma_1x) \). Doing this \( M \) times results in our final estimate for the function \( f \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -227,7 +251,7 @@ where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
<li><a href="._week45-bs018.html">19</a></li>
|
||||
<li><a href="._week45-bs019.html">20</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs011.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,45 +180,36 @@ MathJax.Hub.Config({
|
||||
<a name="part0011"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec10" class="anchor">Building up AdaBoost </h2>
|
||||
<h2 id="___sec10" class="anchor">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
First, for any \( \beta > 0 \), we optimize \( G \) by setting
|
||||
$$
|
||||
G_m(x) = \mathrm{sign} \sum_{i=0}^{n-1} w_i^m I(y_i \ne G_(x_i)),
|
||||
$$
|
||||
|
||||
which is the classifier that minimizes the weighted error rate in predicting \( y \).
|
||||
Let us consider a binary classification problem with two outcomes \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
observations. We define a classification function \( G(x) \) which produces a prediction taking one or the other of the two values
|
||||
\( \{-1,1\} \).
|
||||
|
||||
<p>
|
||||
We can do this by rewriting
|
||||
The error rate of the training sample is then
|
||||
|
||||
$$
|
||||
\exp{-(\beta)}\sum_{y_i=G(x_i)}w_i^m+\exp{(\beta)}\sum_{y_i\ne G(x_i)}w_i^m,
|
||||
\mathrm{\overline{err}}=\frac{1}{n} \sum_{i=0}^{n-1} I(y_i\ne G(x_i)).
|
||||
$$
|
||||
|
||||
which can be rewritten as
|
||||
<p>
|
||||
The iterative procedure starts with defining a weak classifier whose
|
||||
error rate is barely better than random guessing. The iterative
|
||||
procedure in boosting is to sequentially apply a weak
|
||||
classification algorithm to repeatedly modified versions of the data
|
||||
producing a sequence of weak classifiers \( G_m(x) \).
|
||||
|
||||
<p>
|
||||
Here we will express our function \( f(x) \) in terms of \( G(x) \). That is
|
||||
$$
|
||||
(\exp{(\beta)}-\exp{-(\beta)})\sum_{i=0}^{n-1}w_i^mI(y_i\ne G(x_i))+\exp{(-\beta)}\sum_{i=0}^{n-1}w_i^m=0,
|
||||
f_M(x) = \sum_{i=1}^M \beta_m b(x;\gamma_m),
|
||||
$$
|
||||
|
||||
which leads to
|
||||
will be a function of
|
||||
$$
|
||||
\beta_m = \frac{1}{2}\log{\frac{1-\mathrm{\overline{err}}}{\mathrm{\overline{err}}}},
|
||||
$$
|
||||
|
||||
where we have redefined the error as
|
||||
$$
|
||||
\mathrm{\overline{err}}_m=\frac{1}{n}\frac{\sum_{i=0}^{n-1}w_i^mI(y_i\ne G(x_i)}{\sum_{i=0}^{n-1}w_i^m},
|
||||
$$
|
||||
|
||||
which leads to an update of
|
||||
$$
|
||||
f_m(x) = f_{m-1}(x) +\beta_m G_m(x).
|
||||
$$
|
||||
|
||||
This leads to the new weights
|
||||
$$
|
||||
w_i^{m+1} = w_i^m \exp{(-y_i\beta_m G_m(x_i))}
|
||||
G_M(x) = \mathrm{sign} \sum_{i=1}^M \alpha_m G_m(x).
|
||||
$$
|
||||
|
||||
<p>
|
||||
@@ -243,7 +238,7 @@ $$
|
||||
<li><a href="._week45-bs019.html">20</a></li>
|
||||
<li><a href="._week45-bs020.html">21</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs012.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,24 +180,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0012"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec11" class="anchor">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
<h2 id="___sec11" class="anchor">Adaptive Boosting, AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
The algorithm here is rather straightforward. Assume that our weak
|
||||
classifier is a decision tree and we consider a binary set of outputs
|
||||
with \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
observations. Our design matrix is given in terms of the
|
||||
feature/predictor vectors
|
||||
\( \boldsymbol{X}=[\boldsymbol{x}_0\boldsymbol{x}_1\dots\boldsymbol{x}_{p-1}] \). Finally, we define also a
|
||||
classifier determined by our data via a function \( G(x) \). This function tells us how well we are able to classify our outputs/targets \( \boldsymbol{y} \).
|
||||
In our iterative procedure we define thus
|
||||
$$
|
||||
f_m(x) = f_{m-1}(x)+\beta_mG_m(x).
|
||||
$$
|
||||
|
||||
<p>
|
||||
We have already defined the misclassification error \( \mathrm{err} \) as
|
||||
The simplest possible cost function which leads (also simple from a computational point of view) to the AdaBoost algorithm is the
|
||||
exponential cost/loss function defined as
|
||||
$$
|
||||
\mathrm{err}=\frac{1}{n}\sum_{i=0}^{n-1}I(y_i\ne G(x_i)),
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \sum_{i=0}^{n-1}\exp{(-y_i(f_{m-1}(x_i)+\beta G(x_i))}.
|
||||
$$
|
||||
|
||||
where the function \( I() \) is one if we misclassify and zero if we classify correctly.
|
||||
<p>
|
||||
We optimize \( \beta \) and \( G \) for each value of \( m=1:M \) as we did in the regression case.
|
||||
This is normally done in two steps. Let us however first rewrite the cost function as
|
||||
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f}) = \sum_{i=0}^{n-1}w_i^{m}\exp{(-y_i\beta G(x_i))},
|
||||
$$
|
||||
|
||||
where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -221,7 +231,7 @@ where the function \( I() \) is one if we misclassify and zero if we classify co
|
||||
<li><a href="._week45-bs020.html">21</a></li>
|
||||
<li><a href="._week45-bs021.html">22</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs013.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,42 +180,46 @@ MathJax.Hub.Config({
|
||||
<a name="part0013"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec12" class="anchor">Basic Steps of AdaBoost </h2>
|
||||
<h2 id="___sec12" class="anchor">Building up AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
With the above definitions we are now ready to set up the algorithm for AdaBoost.
|
||||
The basic idea is to set up weights which will be used to scale the correctly classified and the misclassified cases.
|
||||
|
||||
<ol>
|
||||
<li> We start by initializing all weights to \( w_i = 1/n \), with \( i=0,1,2,\dots n-1 \). It is easy to see that we must have \( \sum_{i=0}^{n-1}w_i = 1 \).</li>
|
||||
<li> We rewrite the misclassification error as</li>
|
||||
</ol>
|
||||
|
||||
First, for any \( \beta > 0 \), we optimize \( G \) by setting
|
||||
$$
|
||||
\mathrm{\overline{err}}_m=\frac{\sum_{i=0}^{n-1}w_i^m I(y_i\ne G(x_i))}{\sum_{i=0}^{n-1}w_i},
|
||||
G_m(x) = \mathrm{sign} \sum_{i=0}^{n-1} w_i^m I(y_i \ne G_(x_i)),
|
||||
$$
|
||||
|
||||
which is the classifier that minimizes the weighted error rate in predicting \( y \).
|
||||
|
||||
<ol>
|
||||
<li> Then we start looping over all attempts at classifying, namely we start an iterative process for \( m=1:M \), where \( M \) is the final number of classifications. Our given classifier could for example be a plain decision tree.
|
||||
<p>
|
||||
We can do this by rewriting
|
||||
$$
|
||||
\exp{-(\beta)}\sum_{y_i=G(x_i)}w_i^m+\exp{(\beta)}\sum_{y_i\ne G(x_i)}w_i^m,
|
||||
$$
|
||||
|
||||
<ol type="a"></li>
|
||||
<li> Fit then a given classifier to the training set using the weights \( w_i \).</li>
|
||||
<li> Compute then \( \mathrm{err} \) and figure out which events are classified properly and which are classified wrongly.</li>
|
||||
<li> Define a quantity \( \alpha_{m} = \log{(1-\mathrm{\overline{err}}_m)/\mathrm{\overline{err}}_m} \)</li>
|
||||
<li> Set the new weights to \( w_i = w_i\times \exp{(\alpha_m I(y_i\ne G(x_i)} \).</li>
|
||||
</ol>
|
||||
which can be rewritten as
|
||||
$$
|
||||
(\exp{(\beta)}-\exp{-(\beta)})\sum_{i=0}^{n-1}w_i^mI(y_i\ne G(x_i))+\exp{(-\beta)}\sum_{i=0}^{n-1}w_i^m=0,
|
||||
$$
|
||||
|
||||
<li> Compute the new classifier \( G(x)= \sum_{i=0}^{n-1}\alpha_m I(y_i\ne G(x_i) \).</li>
|
||||
</ol>
|
||||
which leads to
|
||||
$$
|
||||
\beta_m = \frac{1}{2}\log{\frac{1-\mathrm{\overline{err}}}{\mathrm{\overline{err}}}},
|
||||
$$
|
||||
|
||||
For the iterations with \( m \le 2 \) the weights are modified
|
||||
individually at each steps. The observations which were misclassified
|
||||
at iteration \( m-1 \) have a weight which is larger than those which were
|
||||
classified properly. As this proceeds, the observations which were
|
||||
difficult to classifiy correctly are given a larger influence. Each
|
||||
new classification step \( m \) is then forced to concentrate on those
|
||||
observations that are missed in the previous iterations.
|
||||
where we have redefined the error as
|
||||
$$
|
||||
\mathrm{\overline{err}}_m=\frac{1}{n}\frac{\sum_{i=0}^{n-1}w_i^mI(y_i\ne G(x_i)}{\sum_{i=0}^{n-1}w_i^m},
|
||||
$$
|
||||
|
||||
which leads to an update of
|
||||
$$
|
||||
f_m(x) = f_{m-1}(x) +\beta_m G_m(x).
|
||||
$$
|
||||
|
||||
This leads to the new weights
|
||||
$$
|
||||
w_i^{m+1} = w_i^m \exp{(-y_i\beta_m G_m(x_i))}
|
||||
$$
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -239,7 +247,7 @@ observations that are missed in the previous iterations.
|
||||
<li><a href="._week45-bs021.html">22</a></li>
|
||||
<li><a href="._week45-bs022.html">23</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs014.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,36 +180,25 @@ MathJax.Hub.Config({
|
||||
<a name="part0014"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec13" class="anchor">AdaBoost Examples </h2>
|
||||
<h2 id="___sec13" class="anchor">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
|
||||
<p>
|
||||
Using <b>Scikit-Learn</b> it is easy to apply the adaptive boosting algorithm, as done here.
|
||||
The algorithm here is rather straightforward. Assume that our weak
|
||||
classifier is a decision tree and we consider a binary set of outputs
|
||||
with \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
observations. Our design matrix is given in terms of the
|
||||
feature/predictor vectors
|
||||
\( \boldsymbol{X}=[\boldsymbol{x}_0\boldsymbol{x}_1\dots\boldsymbol{x}_{p-1}] \). Finally, we define also a
|
||||
classifier determined by our data via a function \( G(x) \). This function tells us how well we are able to classify our outputs/targets \( \boldsymbol{y} \).
|
||||
|
||||
<p>
|
||||
We have already defined the misclassification error \( \mathrm{err} \) as
|
||||
$$
|
||||
\mathrm{err}=\frac{1}{n}\sum_{i=0}^{n-1}I(y_i\ne G(x_i)),
|
||||
$$
|
||||
|
||||
<!-- 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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
|
||||
where the function \( I() \) is one if we misclassify and zero if we classify correctly.
|
||||
|
||||
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
|
||||
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
|
||||
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">"SAMME.R"</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
|
||||
ada_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
|
||||
|
||||
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
|
||||
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
|
||||
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">"SAMME.R"</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
|
||||
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -232,7 +225,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs022.html">23</a></li>
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs015.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,30 +180,42 @@ MathJax.Hub.Config({
|
||||
<a name="part0015"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec14" class="anchor">AdaBoost for Regression </h2>
|
||||
<h2 id="___sec14" class="anchor">Basic Steps of AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
Here we present <a href="https://pdfs.semanticscholar.org/8d49/e2dedb817f2c3330e74b63c5fc86d2399ce3.pdf" target="_self">Drucker's AdaBoost</a> tailored for regression.
|
||||
|
||||
<p>
|
||||
In bagging, each training example is equally likely to be
|
||||
picked. In boosting, the probability of a particular
|
||||
example being in the training set of a particular machine
|
||||
depends on the performance of the prior machines on
|
||||
that example. The following is a modification of
|
||||
Adaboost by Drucker.
|
||||
|
||||
<p>
|
||||
Start by selecting a set of training data \( n \) and assign to each entry a weight \( w_i=1 \) for \( i=1,2,\dots,n \). As we have done earlier, we could pick say \( 80\% \) of the data set for training. The algorithm runs as follows:
|
||||
With the above definitions we are now ready to set up the algorithm for AdaBoost.
|
||||
The basic idea is to set up weights which will be used to scale the correctly classified and the misclassified cases.
|
||||
|
||||
<ol>
|
||||
<li> We define the probability that the training sample \( i \) is in the set by \( p_i = w_i/\sum_iw_i \). We pick \( n \) samples (with replacement) to form our training set. We pick a number uniformly in the range \( [0,\sum_iw_i] \).</li>
|
||||
<li> We choose then a regression machine (for example plain linear regression or a simple decision tree). A given regression machine makes then a hypothesis.</li>
|
||||
<li> Using every member of the training set with the chosen regression machine we obtain then a prediction \( \tilde{y}_i \).</li>
|
||||
<li> We calculate then the loss function \( L_i \) for each training sample. We can use various types of loss function as long as we have a value</li>
|
||||
<li> We start by initializing all weights to \( w_i = 1/n \), with \( i=0,1,2,\dots n-1 \). It is easy to see that we must have \( \sum_{i=0}^{n-1}w_i = 1 \).</li>
|
||||
<li> We rewrite the misclassification error as</li>
|
||||
</ol>
|
||||
|
||||
\( L_i\in [0,1] \).
|
||||
$$
|
||||
\mathrm{\overline{err}}_m=\frac{\sum_{i=0}^{n-1}w_i^m I(y_i\ne G(x_i))}{\sum_{i=0}^{n-1}w_i},
|
||||
$$
|
||||
|
||||
|
||||
<ol>
|
||||
<li> Then we start looping over all attempts at classifying, namely we start an iterative process for \( m=1:M \), where \( M \) is the final number of classifications. Our given classifier could for example be a plain decision tree.
|
||||
|
||||
<ol type="a"></li>
|
||||
<li> Fit then a given classifier to the training set using the weights \( w_i \).</li>
|
||||
<li> Compute then \( \mathrm{err} \) and figure out which events are classified properly and which are classified wrongly.</li>
|
||||
<li> Define a quantity \( \alpha_{m} = \log{(1-\mathrm{\overline{err}}_m)/\mathrm{\overline{err}}_m} \)</li>
|
||||
<li> Set the new weights to \( w_i = w_i\times \exp{(\alpha_m I(y_i\ne G(x_i)} \).</li>
|
||||
</ol>
|
||||
|
||||
<li> Compute the new classifier \( G(x)= \sum_{i=0}^{n-1}\alpha_m I(y_i\ne G(x_i) \).</li>
|
||||
</ol>
|
||||
|
||||
For the iterations with \( m \le 2 \) the weights are modified
|
||||
individually at each steps. The observations which were misclassified
|
||||
at iteration \( m-1 \) have a weight which is larger than those which were
|
||||
classified properly. As this proceeds, the observations which were
|
||||
difficult to classifiy correctly are given a larger influence. Each
|
||||
new classification step \( m \) is then forced to concentrate on those
|
||||
observations that are missed in the previous iterations.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -227,7 +243,7 @@ Start by selecting a set of training data \( n \) and assign to each entry a wei
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs016.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,18 +180,36 @@ MathJax.Hub.Config({
|
||||
<a name="part0016"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec15" class="anchor">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
<h2 id="___sec15" class="anchor">AdaBoost Examples </h2>
|
||||
|
||||
<p>
|
||||
Gradient boosting is again a similar technique to Adaptive boosting,
|
||||
it combines so-called weak classifiers or regressors into a strong
|
||||
method via a series of iterations.
|
||||
Using <b>Scikit-Learn</b> it is easy to apply the adaptive boosting algorithm, as done here.
|
||||
|
||||
<p>
|
||||
In order to understand the method, let us illustrate its basics by
|
||||
bringing back the essential steps in linear regression, where our cost
|
||||
function was the least squares function.
|
||||
|
||||
<!-- 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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
|
||||
|
||||
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
|
||||
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
|
||||
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">"SAMME.R"</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
|
||||
ada_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
|
||||
|
||||
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
|
||||
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
|
||||
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">"SAMME.R"</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
|
||||
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -213,6 +235,8 @@ function was the least squares function.
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs017.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,37 +180,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0017"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec16" class="anchor">The Squared-Error again! Steepest Descent </h2>
|
||||
<h2 id="___sec16" class="anchor">AdaBoost for Regression </h2>
|
||||
|
||||
<p>
|
||||
We start again with our cost function \( {\cal C}(\boldsymbol{y}m\boldsymbol{f})=\sum_{i=0}^{n-1}{\cal L}(y_i, f(x_i)) \) where we want to minimize
|
||||
This means that for every iteration, we need to optimize
|
||||
|
||||
$$
|
||||
(\hat{\boldsymbol{f}}) = \mathrm{argmin}_{\boldsymbol{f}}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
$$
|
||||
Here we present <a href="https://pdfs.semanticscholar.org/8d49/e2dedb817f2c3330e74b63c5fc86d2399ce3.pdf" target="_self">Drucker's AdaBoost</a> tailored for regression.
|
||||
|
||||
<p>
|
||||
We define a real function \( h_m(x) \) that defines our final function \( f_M(x) \) as
|
||||
$$
|
||||
f_M(x) = \sum_{m=0}^M h_m(x).
|
||||
$$
|
||||
In bagging, each training example is equally likely to be
|
||||
picked. In boosting, the probability of a particular
|
||||
example being in the training set of a particular machine
|
||||
depends on the performance of the prior machines on
|
||||
that example. The following is a modification of
|
||||
Adaboost by Drucker.
|
||||
|
||||
<p>
|
||||
In the steepest decent approach we approximate \( h_m(x) = -\rho_m g_m(x) \), where \( \rho_m \) is a scalar and \( g_m(x) \) the gradient defined as
|
||||
$$
|
||||
g_m(x_i) = \left[ \frac{\partial {\cal L}(y_i, f(x_i))}{\partial f(x_i)}\right]_{f(x_i)=f_{m-1}(x_i)}.
|
||||
$$
|
||||
Start by selecting a set of training data \( n \) and assign to each entry a weight \( w_i=1 \) for \( i=1,2,\dots,n \). As we have done earlier, we could pick say \( 80\% \) of the data set for training. The algorithm runs as follows:
|
||||
|
||||
<p>
|
||||
With the new gradient we can update \( f_m(x) = f_{m-1}(x) -\rho_m g_m(x) \). Using the above squared-error function we see that
|
||||
the gradient is \( g_m(x_i) = -2(y_i-f(x_i)) \).
|
||||
<ol>
|
||||
<li> We define the probability that the training sample \( i \) is in the set by \( p_i = w_i/\sum_iw_i \). We pick \( n \) samples (with replacement) to form our training set. We pick a number uniformly in the range \( [0,\sum_iw_i] \).</li>
|
||||
<li> We choose then a regression machine (for example plain linear regression or a simple decision tree). A given regression machine makes then a hypothesis.</li>
|
||||
<li> Using every member of the training set with the chosen regression machine we obtain then a prediction \( \tilde{y}_i \).</li>
|
||||
<li> We calculate then the loss function \( L_i \) for each training sample. We can use various types of loss function as long as we have a value</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
Choosing \( f_0(x)=0 \) we obtain \( g_m(x) = -2y_i \) and inserting this into the minimization problem for the cost function we have
|
||||
$$
|
||||
(\rho_1) = \mathrm{argmin}_{\rho}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i+2\rho y_i)^2.
|
||||
$$
|
||||
\( L_i\in [0,1] \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -232,6 +229,9 @@ $$
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs018.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,20 +180,17 @@ MathJax.Hub.Config({
|
||||
<a name="part0018"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec17" class="anchor">Steepest Descent Example </h2>
|
||||
<h2 id="___sec17" class="anchor">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
Optimizing with respect to \( \rho \) we obtain (taking the derivative) that \( \rho_1 = -1/2 \). We have then that
|
||||
$$
|
||||
f_1(x) = f_{0}(x) -\rho_1 g_1(x)=-y_i.
|
||||
$$
|
||||
Gradient boosting is again a similar technique to Adaptive boosting,
|
||||
it combines so-called weak classifiers or regressors into a strong
|
||||
method via a series of iterations.
|
||||
|
||||
We can then proceed and compute
|
||||
$$
|
||||
g_2(x_i) = \left[ \frac{\partial {\cal L}(y_i, f(x_i))}{\partial f(x_i)}\right]_{f(x_i)=f_{1}(x_i)=y_i}=-4y_i,
|
||||
$$
|
||||
|
||||
and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \( m=M \). We can modify the steepest descent method, or steepest boosting, by introducing what is called <b>gradient boosting</b>.
|
||||
<p>
|
||||
In order to understand the method, let us illustrate its basics by
|
||||
bringing back the essential steps in linear regression, where our cost
|
||||
function was the least squares function.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -214,6 +215,8 @@ and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \(
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs019.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,30 +180,39 @@ MathJax.Hub.Config({
|
||||
<a name="part0019"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec18" class="anchor">Gradient Boosting, algorithm </h2>
|
||||
<h2 id="___sec18" class="anchor">The Squared-Error again! Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
Suppose we have a cost function \( C(f)=\sum_{i=0}^{n-1}L(y_i, f(x_i)) \) where \( y_i \) is our target and \( f(x_i) \) the function which is meant to model \( y_i \). The above cost function could be our standard squared-error function
|
||||
We start again with our cost function \( {\cal C}(\boldsymbol{y}m\boldsymbol{f})=\sum_{i=0}^{n-1}{\cal L}(y_i, f(x_i)) \) where we want to minimize
|
||||
This means that for every iteration, we need to optimize
|
||||
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f})=\sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
(\hat{\boldsymbol{f}}) = \mathrm{argmin}_{\boldsymbol{f}}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
$$
|
||||
|
||||
<p>
|
||||
The way we proceed in an iterative fashion is to
|
||||
We define a real function \( h_m(x) \) that defines our final function \( f_M(x) \) as
|
||||
$$
|
||||
f_M(x) = \sum_{m=0}^M h_m(x).
|
||||
$$
|
||||
|
||||
<ol>
|
||||
<li> Initialize our estimate \( f_0(x) \).</li>
|
||||
<li> For \( m=1:M \), we
|
||||
<p>
|
||||
In the steepest decent approach we approximate \( h_m(x) = -\rho_m g_m(x) \), where \( \rho_m \) is a scalar and \( g_m(x) \) the gradient defined as
|
||||
$$
|
||||
g_m(x_i) = \left[ \frac{\partial {\cal L}(y_i, f(x_i))}{\partial f(x_i)}\right]_{f(x_i)=f_{m-1}(x_i)}.
|
||||
$$
|
||||
|
||||
<ol type="a"></li>
|
||||
<li> compute the negative gradient vector \( \boldsymbol{u}_m = -\partial C(\boldsymbol{y},\boldsymbol{f})/\partial \boldsymbol{f}(x) \) at \( f(x) = f_{m-1}(x) \);</li>
|
||||
<li> fit the so-called base-learner to the negative gradient \( h_m(u_m,x) \);</li>
|
||||
<li> update the estimate \( f_m(x) = f_{m-1}(x)+\nu h_m(u_m,x) \);</li>
|
||||
</ol>
|
||||
<p>
|
||||
With the new gradient we can update \( f_m(x) = f_{m-1}(x) -\rho_m g_m(x) \). Using the above squared-error function we see that
|
||||
the gradient is \( g_m(x_i) = -2(y_i-f(x_i)) \).
|
||||
|
||||
<li> The final estimate is then \( f_M(x) = \sum_{m=1}^M\nu h_m(u_m,x) \).</li>
|
||||
</ol>
|
||||
<p>
|
||||
Choosing \( f_0(x)=0 \) we obtain \( g_m(x) = -2y_i \) and inserting this into the minimization problem for the cost function we have
|
||||
$$
|
||||
(\rho_1) = \mathrm{argmin}_{\rho}\hspace{0.1cm} \sum_{i=0}^{n-1}(y_i+2\rho y_i)^2.
|
||||
$$
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -221,6 +234,8 @@ The way we proceed in an iterative fashion is to
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs020.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,10 +180,20 @@ MathJax.Hub.Config({
|
||||
<a name="part0020"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec19" class="anchor">Gradient Boosting Example, Regression </h2>
|
||||
<h2 id="___sec19" class="anchor">Steepest Descent Example </h2>
|
||||
|
||||
<p>
|
||||
We discuss here the difference between the steepest descent approach and gradient boosting by repeating our simple regression example above.
|
||||
Optimizing with respect to \( \rho \) we obtain (taking the derivative) that \( \rho_1 = -1/2 \). We have then that
|
||||
$$
|
||||
f_1(x) = f_{0}(x) -\rho_1 g_1(x)=-y_i.
|
||||
$$
|
||||
|
||||
We can then proceed and compute
|
||||
$$
|
||||
g_2(x_i) = \left[ \frac{\partial {\cal L}(y_i, f(x_i))}{\partial f(x_i)}\right]_{f(x_i)=f_{1}(x_i)=y_i}=-4y_i,
|
||||
$$
|
||||
|
||||
and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \( m=M \). We can modify the steepest descent method, or steepest boosting, by introducing what is called <b>gradient boosting</b>.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -202,6 +216,8 @@ We discuss here the difference between the steepest descent approach and gradien
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs021.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,58 +180,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0021"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec20" class="anchor">Gradient Boosting, Examples of Regression </h2>
|
||||
<h2 id="___sec20" class="anchor">Gradient Boosting, algorithm </h2>
|
||||
|
||||
<p>
|
||||
Suppose we have a cost function \( C(f)=\sum_{i=0}^{n-1}L(y_i, f(x_i)) \) where \( y_i \) is our target and \( f(x_i) \) the function which is meant to model \( y_i \). The above cost function could be our standard squared-error function
|
||||
$$
|
||||
C(\boldsymbol{y},\boldsymbol{f})=\sum_{i=0}^{n-1}(y_i-f(x_i))^2.
|
||||
$$
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> GradientBoostingRegressor
|
||||
<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> StandardScaler
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error
|
||||
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
maxdegree <span style="color: #666666">=</span> <span style="color: #666666">6</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Make data set.</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)
|
||||
|
||||
error <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
bias <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
variance <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
polydegree <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(x, y, test_size<span style="color: #666666">=0.2</span>)
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
<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>(<span style="color: #666666">1</span>,maxdegree):
|
||||
model <span style="color: #666666">=</span> GradientBoostingRegressor(max_depth<span style="color: #666666">=</span>degree, n_estimators<span style="color: #666666">=100</span>, learning_rate<span style="color: #666666">=1.0</span>)
|
||||
model<span style="color: #666666">.</span>fit(X_train_scaled,y_train)
|
||||
y_pred <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
polydegree[degree] <span style="color: #666666">=</span> degree
|
||||
error[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>) )
|
||||
bias[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred))<span style="color: #666666">**2</span> )
|
||||
variance[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred) )
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'{} >= {} + {} = {}'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdegree<span style="color: #666666">-1</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'Error'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, bias, label<span style="color: #666666">=</span><span style="color: #BA2121">'bias'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, variance, label<span style="color: #666666">=</span><span style="color: #BA2121">'Variance'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
save_fig(<span style="color: #BA2121">"gdregression"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
The way we proceed in an iterative fashion is to
|
||||
|
||||
<ol>
|
||||
<li> Initialize our estimate \( f_0(x) \).</li>
|
||||
<li> For \( m=1:M \), we
|
||||
|
||||
<ol type="a"></li>
|
||||
<li> compute the negative gradient vector \( \boldsymbol{u}_m = -\partial C(\boldsymbol{y},\boldsymbol{f})/\partial \boldsymbol{f}(x) \) at \( f(x) = f_{m-1}(x) \);</li>
|
||||
<li> fit the so-called base-learner to the negative gradient \( h_m(u_m,x) \);</li>
|
||||
<li> update the estimate \( f_m(x) = f_{m-1}(x)+\nu h_m(u_m,x) \);</li>
|
||||
</ol>
|
||||
|
||||
<li> The final estimate is then \( f_M(x) = \sum_{m=1}^M\nu h_m(u_m,x) \).</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -247,6 +223,8 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs022.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,51 +180,11 @@ MathJax.Hub.Config({
|
||||
<a name="part0022"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec21" class="anchor">Gradient Boosting, Classification Example </h2>
|
||||
<h2 id="___sec21" class="anchor">Gradient Boosting Example, Regression </h2>
|
||||
|
||||
<p>
|
||||
We discuss here the difference between the steepest descent approach and gradient boosting by repeating our simple regression example above.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.datasets</span> <span style="color: #008000; font-weight: bold">import</span> load_breast_cancer
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> GradientBoostingClassifier
|
||||
<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_validate
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
gd_clf <span style="color: #666666">=</span> GradientBoostingClassifier(max_depth<span style="color: #666666">=3</span>, n_estimators<span style="color: #666666">=100</span>, learning_rate<span style="color: #666666">=1.0</span>)
|
||||
gd_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(gd_clf,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(gd_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffierconfusion"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffierroc"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffiercgain"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -240,6 +204,8 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs023.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,24 +180,57 @@ MathJax.Hub.Config({
|
||||
<a name="part0023"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec22" class="anchor">XGBoost: Extreme Gradient Boosting </h2>
|
||||
|
||||
<h2 id="___sec22" class="anchor">Gradient Boosting, Examples of Regression </h2>
|
||||
<p>
|
||||
<a href="https://github.com/dmlc/xgboost" target="_self">XGBoost</a> or Extreme Gradient
|
||||
Boosting, is an optimized distributed gradient boosting library
|
||||
designed to be highly efficient, flexible and portable. It implements
|
||||
machine learning algorithms under the Gradient Boosting
|
||||
framework. XGBoost provides a parallel tree boosting that solve many
|
||||
data science problems in a fast and accurate way. See the <a href="https://arxiv.org/abs/1603.02754" target="_self">article by Chen and Guestrin</a>.
|
||||
|
||||
<p>
|
||||
The authors design and build a highly scalable end-to-end tree
|
||||
boosting system. It has a theoretically justified weighted quantile
|
||||
sketch for efficient proposal calculation. It introduces a novel sparsity-aware algorithm for parallel tree learning and an effective cache-aware block structure for out-of-core tree learning.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> GradientBoostingRegressor
|
||||
<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> StandardScaler
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error
|
||||
|
||||
<p>
|
||||
It is now the algorithm which wins essentially all ML competitions!!!
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
maxdegree <span style="color: #666666">=</span> <span style="color: #666666">6</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Make data set.</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)
|
||||
|
||||
error <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
bias <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
variance <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
polydegree <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(x, y, test_size<span style="color: #666666">=0.2</span>)
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
<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>(<span style="color: #666666">1</span>,maxdegree):
|
||||
model <span style="color: #666666">=</span> GradientBoostingRegressor(max_depth<span style="color: #666666">=</span>degree, n_estimators<span style="color: #666666">=100</span>, learning_rate<span style="color: #666666">=1.0</span>)
|
||||
model<span style="color: #666666">.</span>fit(X_train_scaled,y_train)
|
||||
y_pred <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
polydegree[degree] <span style="color: #666666">=</span> degree
|
||||
error[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>) )
|
||||
bias[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred))<span style="color: #666666">**2</span> )
|
||||
variance[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred) )
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdegree<span style="color: #666666">-1</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'Error'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, bias, label<span style="color: #666666">=</span><span style="color: #BA2121">'bias'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, variance, label<span style="color: #666666">=</span><span style="color: #BA2121">'Variance'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
save_fig(<span style="color: #BA2121">"gdregression"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -212,6 +249,8 @@ It is now the algorithm which wins essentially all ML competitions!!!
|
||||
<li class="active"><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs024.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,56 +180,49 @@ MathJax.Hub.Config({
|
||||
<a name="part0024"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec23" class="anchor">Regression Case </h2>
|
||||
|
||||
<h2 id="___sec23" class="anchor">Gradient Boosting, Classification Example </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">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">xgboost</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">xgb</span>
|
||||
<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> StandardScaler
|
||||
<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> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.datasets</span> <span style="color: #008000; font-weight: bold">import</span> load_breast_cancer
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> GradientBoostingClassifier
|
||||
<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_validate
|
||||
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
maxdegree <span style="color: #666666">=</span> <span style="color: #666666">6</span>
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Make data set.</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)
|
||||
|
||||
error <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
bias <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
variance <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
polydegree <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdegree)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(x, y, test_size<span style="color: #666666">=0.2</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
<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>(maxdegree):
|
||||
model <span style="color: #666666">=</span> xgb<span style="color: #666666">.</span>XGBRegressor(objective <span style="color: #666666">=</span><span style="color: #BA2121">'reg:squarederror'</span>, colsaobjective <span style="color: #666666">=</span><span style="color: #BA2121">'reg:squarederror'</span>, colsample_bytree <span style="color: #666666">=</span> <span style="color: #666666">0.3</span>, learning_rate <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>,max_depth <span style="color: #666666">=</span> degree, alpha <span style="color: #666666">=</span> <span style="color: #666666">10</span>, n_estimators <span style="color: #666666">=</span> <span style="color: #666666">200</span>)
|
||||
gd_clf <span style="color: #666666">=</span> GradientBoostingClassifier(max_depth<span style="color: #666666">=3</span>, n_estimators<span style="color: #666666">=100</span>, learning_rate<span style="color: #666666">=1.0</span>)
|
||||
gd_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(gd_clf,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000">print</span>(accuracy)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(gd_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
model<span style="color: #666666">.</span>fit(X_train_scaled,y_train)
|
||||
y_pred <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
polydegree[degree] <span style="color: #666666">=</span> degree
|
||||
error[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>) )
|
||||
bias[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred))<span style="color: #666666">**2</span> )
|
||||
variance[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred) )
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'{} >= {} + {} = {}'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdegree<span style="color: #666666">-1</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'Error'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, bias, label<span style="color: #666666">=</span><span style="color: #BA2121">'bias'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, variance, label<span style="color: #666666">=</span><span style="color: #BA2121">'Variance'</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffierconfusion"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffierroc"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffiercgain"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -245,6 +242,8 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li class="active"><a href="._week45-bs024.html">25</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs025.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -176,67 +180,25 @@ MathJax.Hub.Config({
|
||||
<a name="part0025"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec24" class="anchor">Xgboost on the Cancer Data </h2>
|
||||
<h2 id="___sec24" class="anchor">XGBoost: Extreme Gradient Boosting </h2>
|
||||
|
||||
<p>
|
||||
As you will see from the confusion matrix below, XGBoots does an excellent job on the Wisconsin cancer data and outperforms essentially all agorithms we have discussed till now.
|
||||
<a href="https://github.com/dmlc/xgboost" target="_self">XGBoost</a> or Extreme Gradient
|
||||
Boosting, is an optimized distributed gradient boosting library
|
||||
designed to be highly efficient, flexible and portable. It implements
|
||||
machine learning algorithms under the Gradient Boosting
|
||||
framework. XGBoost provides a parallel tree boosting that solve many
|
||||
data science problems in a fast and accurate way. See the <a href="https://arxiv.org/abs/1603.02754" target="_self">article by Chen and Guestrin</a>.
|
||||
|
||||
<p>
|
||||
The authors design and build a highly scalable end-to-end tree
|
||||
boosting system. It has a theoretically justified weighted quantile
|
||||
sketch for efficient proposal calculation. It introduces a novel sparsity-aware algorithm for parallel tree learning and an effective cache-aware block structure for out-of-core tree learning.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.datasets</span> <span style="color: #008000; font-weight: bold">import</span> load_breast_cancer
|
||||
<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> LabelEncoder
|
||||
<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_validate
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">xgboost</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">xgb</span>
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
xg_clf <span style="color: #666666">=</span> xgb<span style="color: #666666">.</span>XGBClassifier()
|
||||
xg_clf<span style="color: #666666">.</span>fit(X_train_scaled,y_train)
|
||||
|
||||
y_test <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(xg_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
save_fig(<span style="color: #BA2121">"xdclassiffierconfusion"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"xdclassiffierroc"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffiercgain"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
|
||||
xgb<span style="color: #666666">.</span>plot_tree(xg_clf,num_trees<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'figure.figsize'</span>] <span style="color: #666666">=</span> [<span style="color: #666666">50</span>, <span style="color: #666666">10</span>]
|
||||
save_fig(<span style="color: #BA2121">"xgtree"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
xgb<span style="color: #666666">.</span>plot_importance(xg_clf)
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'figure.figsize'</span>] <span style="color: #666666">=</span> [<span style="color: #666666">5</span>, <span style="color: #666666">5</span>]
|
||||
save_fig(<span style="color: #BA2121">"xgparams"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
It is now the algorithm which wins essentially all ML competitions!!!
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -252,6 +214,9 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week45-bs023.html">24</a></li>
|
||||
<li><a href="._week45-bs024.html">25</a></li>
|
||||
<li class="active"><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs026.html">27</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs026.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -41,64 +41,66 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -136,31 +138,33 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs001.html#___sec0" style="font-size: 80%;">Overview of week 45</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs003.html#___sec2" style="font-size: 80%;">Random forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs004.html#___sec3" style="font-size: 80%;">Random Forest Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs005.html#___sec4" style="font-size: 80%;">Random Forests Compared with other Methods on the Cancer Data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs006.html#___sec5" style="font-size: 80%;">Compare Bagging on Trees with Random Forests</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs007.html#___sec6" style="font-size: 80%;">Boosting, a Bird's Eye View</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs008.html#___sec7" style="font-size: 80%;">What is boosting? Additive Modelling/Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs009.html#___sec8" style="font-size: 80%;">Iterative Fitting, Regression and Squared-error Cost Function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs010.html#___sec9" style="font-size: 80%;">Squared-Error Example and Iterative Fitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs011.html#___sec10" style="font-size: 80%;">Iterative Fitting, Classification and AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs012.html#___sec11" style="font-size: 80%;">Adaptive Boosting, AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs013.html#___sec12" style="font-size: 80%;">Building up AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs014.html#___sec13" style="font-size: 80%;">Adaptive boosting: AdaBoost, Basic Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs015.html#___sec14" style="font-size: 80%;">Basic Steps of AdaBoost</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs016.html#___sec15" style="font-size: 80%;">AdaBoost Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs017.html#___sec16" style="font-size: 80%;">AdaBoost for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs018.html#___sec17" style="font-size: 80%;">Gradient boosting: Basics with Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs019.html#___sec18" style="font-size: 80%;">The Squared-Error again! Steepest Descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs020.html#___sec19" style="font-size: 80%;">Steepest Descent Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs021.html#___sec20" style="font-size: 80%;">Gradient Boosting, algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs022.html#___sec21" style="font-size: 80%;">Gradient Boosting Example, Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs023.html#___sec22" style="font-size: 80%;">Gradient Boosting, Examples of Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs024.html#___sec23" style="font-size: 80%;">Gradient Boosting, Classification Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs025.html#___sec24" style="font-size: 80%;">XGBoost: Extreme Gradient Boosting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs026.html#___sec25" style="font-size: 80%;">Regression Case</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week45-bs027.html#___sec26" style="font-size: 80%;">Xgboost on the Cancer Data</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -195,7 +199,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 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 31, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -219,7 +223,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week45-bs008.html">9</a></li>
|
||||
<li><a href="._week45-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week45-bs025.html">26</a></li>
|
||||
<li><a href="._week45-bs027.html">28</a></li>
|
||||
<li><a href="._week45-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Sep 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 31, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -159,7 +159,28 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec0">Random forests </h2>
|
||||
<h2 id="___sec0">Overview of week 45 </h2>
|
||||
|
||||
<ul>
|
||||
<p><li> "Thursday: Wrapping up from last week. Bagging and Random forests.</li>
|
||||
<p><li> "Friday: Boosting and gradient boosting</li>
|
||||
</ul>
|
||||
<p>
|
||||
|
||||
Geron's chapter 7. See also lecture from <a href="https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf" target="_blank">STK-IN4300, lecture 7</a>. Chapter 9.2 of Hastie et al contains also a good discussion.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec1">Thursday </h2>
|
||||
|
||||
<p>
|
||||
Bagging, voting and random forests.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec2">Random forests </h2>
|
||||
|
||||
<p>
|
||||
Random forests provide an improvement over bagged trees by way of a
|
||||
@@ -205,7 +226,7 @@ this setting.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec1">Random Forest Algorithm </h2>
|
||||
<h2 id="___sec3">Random Forest Algorithm </h2>
|
||||
The algorithm described here can be applied to both classification and regression problems.
|
||||
|
||||
<p>
|
||||
@@ -236,7 +257,7 @@ We will grow of forest of say \( B \) trees.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec2">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<h2 id="___sec4">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -252,20 +273,20 @@ We will grow of forest of say \( B \) trees.
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22"># Logistic Regression</span>
|
||||
logreg = LogisticRegression(solver=<span style="color: #CD5555">'lbfgs'</span>)
|
||||
logreg.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Logistic Regression: {:.2f}"</span>.format(logreg.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Logistic Regression: {:.2f}"</span>.format(logreg.score(X_test,y_test)))
|
||||
<span style="color: #228B22"># Support vector machine</span>
|
||||
svm = SVC(gamma=<span style="color: #CD5555">'auto'</span>, C=<span style="color: #B452CD">100</span>)
|
||||
svm.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with SVM: {:.2f}"</span>.format(svm.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with SVM: {:.2f}"</span>.format(svm.score(X_test,y_test)))
|
||||
<span style="color: #228B22"># Decision Trees</span>
|
||||
deep_tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #658b00">None</span>)
|
||||
deep_tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #8B008B; font-weight: bold">None</span>)
|
||||
deep_tree_clf.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees: {:.2f}"</span>.format(deep_tree_clf.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees: {:.2f}"</span>.format(deep_tree_clf.score(X_test,y_test)))
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -274,13 +295,13 @@ X_train_scaled = scaler.transform(X_train)
|
||||
X_test_scaled = scaler.transform(X_test)
|
||||
<span style="color: #228B22"># Logistic Regression</span>
|
||||
logreg.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #228B22"># Support Vector Machine</span>
|
||||
svm.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy SVM with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy SVM with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #228B22"># Decision Trees</span>
|
||||
deep_tree_clf.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span>.format(deep_tree_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span>.format(deep_tree_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> RandomForestClassifier
|
||||
@@ -292,13 +313,13 @@ Random_Forest_model = RandomForestClassifier(n_estimators=<span style="color: #B
|
||||
Random_Forest_model.fit(X_train_scaled, y_train)
|
||||
<span style="color: #228B22">#Cross validation</span>
|
||||
accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=<span style="color: #B452CD">10</span>)[<span style="color: #CD5555">'test_score'</span>]
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(Random_Forest_model.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(accuracy)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(Random_Forest_model.score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = Random_Forest_model.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
plt.show()
|
||||
y_probas = Random_Forest_model.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
@@ -310,13 +331,13 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec3">Compare Bagging on Trees with Random Forests </h2>
|
||||
<h2 id="___sec5">Compare Bagging on Trees with Random Forests </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>bag_clf = BaggingClassifier(
|
||||
DecisionTreeClassifier(splitter=<span style="color: #CD5555">"random"</span>, max_leaf_nodes=<span style="color: #B452CD">16</span>, random_state=<span style="color: #B452CD">42</span>),
|
||||
n_estimators=<span style="color: #B452CD">500</span>, max_samples=<span style="color: #B452CD">1.0</span>, bootstrap=<span style="color: #658b00">True</span>, n_jobs=-<span style="color: #B452CD">1</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
n_estimators=<span style="color: #B452CD">500</span>, max_samples=<span style="color: #B452CD">1.0</span>, bootstrap=<span style="color: #8B008B; font-weight: bold">True</span>, n_jobs=-<span style="color: #B452CD">1</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
@@ -333,7 +354,7 @@ np.sum(y_pred == y_pred_rf) / <span style="color: #658b00">len</span>(y_pred)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec4">Boosting, a Bird's Eye View </h2>
|
||||
<h2 id="___sec6">Boosting, a Bird's Eye View </h2>
|
||||
|
||||
<p>
|
||||
The basic idea is to combine weak classifiers in order to create a good
|
||||
@@ -350,7 +371,7 @@ them with a factor.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec5">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
<h2 id="___sec7">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
Boosting is a way of fitting an additive expansion in a set of
|
||||
@@ -410,7 +431,7 @@ In iterative fitting or additive modeling, we minimize the cost function with re
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec6">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
<h2 id="___sec8">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
|
||||
<p>
|
||||
The way we proceed is as follows (here we specialize to the squared-error cost function)
|
||||
@@ -436,7 +457,7 @@ at the internal nodes, and the predictions at the terminal nodes.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec7">Squared-Error Example and Iterative Fitting </h2>
|
||||
<h2 id="___sec9">Squared-Error Example and Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.
|
||||
@@ -494,7 +515,7 @@ The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec8">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
<h2 id="___sec10">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
Let us consider a binary classification problem with two outcomes \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
@@ -535,7 +556,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec9">Adaptive Boosting, AdaBoost </h2>
|
||||
<h2 id="___sec11">Adaptive Boosting, AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
In our iterative procedure we define thus
|
||||
@@ -569,7 +590,7 @@ where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec10">Building up AdaBoost </h2>
|
||||
<h2 id="___sec12">Building up AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
First, for any \( \beta > 0 \), we optimize \( G \) by setting
|
||||
@@ -627,7 +648,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec11">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
<h2 id="___sec13">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
|
||||
<p>
|
||||
The algorithm here is rather straightforward. Assume that our weak
|
||||
@@ -651,7 +672,7 @@ where the function \( I() \) is one if we misclassify and zero if we classify co
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec12">Basic Steps of AdaBoost </h2>
|
||||
<h2 id="___sec14">Basic Steps of AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
With the above definitions we are now ready to set up the algorithm for AdaBoost.
|
||||
@@ -692,7 +713,7 @@ observations that are missed in the previous iterations.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec13">AdaBoost Examples </h2>
|
||||
<h2 id="___sec15">AdaBoost Examples </h2>
|
||||
|
||||
<p>
|
||||
Using <b>Scikit-Learn</b> it is easy to apply the adaptive boosting algorithm, as done here.
|
||||
@@ -714,7 +735,7 @@ ada_clf = AdaBoostClassifier(
|
||||
algorithm=<span style="color: #CD5555">"SAMME.R"</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
ada_clf.fit(X_train_scaled, y_train)
|
||||
y_pred = ada_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
plt.show()
|
||||
y_probas = ada_clf.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
@@ -726,7 +747,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec14">AdaBoost for Regression </h2>
|
||||
<h2 id="___sec16">AdaBoost for Regression </h2>
|
||||
|
||||
<p>
|
||||
Here we present <a href="https://pdfs.semanticscholar.org/8d49/e2dedb817f2c3330e74b63c5fc86d2399ce3.pdf" target="_blank">Drucker's AdaBoost</a> tailored for regression.
|
||||
@@ -755,7 +776,7 @@ Start by selecting a set of training data \( n \) and assign to each entry a wei
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec15">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
<h2 id="___sec17">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
Gradient boosting is again a similar technique to Adaptive boosting,
|
||||
@@ -770,7 +791,7 @@ function was the least squares function.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec16">The Squared-Error again! Steepest Descent </h2>
|
||||
<h2 id="___sec18">The Squared-Error again! Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
We start again with our cost function \( {\cal C}(\boldsymbol{y}m\boldsymbol{f})=\sum_{i=0}^{n-1}{\cal L}(y_i, f(x_i)) \) where we want to minimize
|
||||
@@ -813,7 +834,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec17">Steepest Descent Example </h2>
|
||||
<h2 id="___sec19">Steepest Descent Example </h2>
|
||||
|
||||
<p>
|
||||
Optimizing with respect to \( \rho \) we obtain (taking the derivative) that \( \rho_1 = -1/2 \). We have then that
|
||||
@@ -835,7 +856,7 @@ and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \(
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec18">Gradient Boosting, algorithm </h2>
|
||||
<h2 id="___sec20">Gradient Boosting, algorithm </h2>
|
||||
|
||||
<p>
|
||||
Suppose we have a cost function \( C(f)=\sum_{i=0}^{n-1}L(y_i, f(x_i)) \) where \( y_i \) is our target and \( f(x_i) \) the function which is meant to model \( y_i \). The above cost function could be our standard squared-error function
|
||||
@@ -863,7 +884,7 @@ The way we proceed in an iterative fashion is to
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec19">Gradient Boosting Example, Regression </h2>
|
||||
<h2 id="___sec21">Gradient Boosting Example, Regression </h2>
|
||||
|
||||
<p>
|
||||
We discuss here the difference between the steepest descent approach and gradient boosting by repeating our simple regression example above.
|
||||
@@ -871,7 +892,7 @@ We discuss here the difference between the steepest descent approach and gradien
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec20">Gradient Boosting, Examples of Regression </h2>
|
||||
<h2 id="___sec22">Gradient Boosting, Examples of Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -908,11 +929,11 @@ X_test_scaled = scaler.transform(X_test)
|
||||
error[degree] = np.mean( np.mean((y_test - y_pred)**<span style="color: #B452CD">2</span>) )
|
||||
bias[degree] = np.mean( (y_test - np.mean(y_pred))**<span style="color: #B452CD">2</span> )
|
||||
variance[degree] = np.mean( np.var(y_pred) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdegree-<span style="color: #B452CD">1</span>)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'Error'</span>)
|
||||
@@ -926,7 +947,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec21">Gradient Boosting, Classification Example </h2>
|
||||
<h2 id="___sec23">Gradient Boosting, Classification Example </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -942,8 +963,8 @@ plt.show()
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -955,12 +976,12 @@ gd_clf = GradientBoostingClassifier(max_depth=<span style="color: #B452CD">3</sp
|
||||
gd_clf.fit(X_train_scaled, y_train)
|
||||
<span style="color: #228B22">#Cross validation</span>
|
||||
accuracy = cross_validate(gd_clf,X_test_scaled,y_test,cv=<span style="color: #B452CD">10</span>)[<span style="color: #CD5555">'test_score'</span>]
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(gd_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(accuracy)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(gd_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = gd_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #CD5555">"gdclassiffierconfusion"</span>)
|
||||
plt.show()
|
||||
y_probas = gd_clf.predict_proba(X_test_scaled)
|
||||
@@ -975,7 +996,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec22">XGBoost: Extreme Gradient Boosting </h2>
|
||||
<h2 id="___sec24">XGBoost: Extreme Gradient Boosting </h2>
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/dmlc/xgboost" target="_blank">XGBoost</a> or Extreme Gradient
|
||||
@@ -996,7 +1017,7 @@ It is now the algorithm which wins essentially all ML competitions!!!
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec23">Regression Case </h2>
|
||||
<h2 id="___sec25">Regression Case </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1035,11 +1056,11 @@ X_test_scaled = scaler.transform(X_test)
|
||||
error[degree] = np.mean( np.mean((y_test - y_pred)**<span style="color: #B452CD">2</span>) )
|
||||
bias[degree] = np.mean( (y_test - np.mean(y_pred))**<span style="color: #B452CD">2</span> )
|
||||
variance[degree] = np.mean( np.var(y_pred) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdegree-<span style="color: #B452CD">1</span>)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'Error'</span>)
|
||||
@@ -1052,7 +1073,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec24">Xgboost on the Cancer Data </h2>
|
||||
<h2 id="___sec26">Xgboost on the Cancer Data </h2>
|
||||
|
||||
<p>
|
||||
As you will see from the confusion matrix below, XGBoots does an excellent job on the Wisconsin cancer data and outperforms essentially all agorithms we have discussed till now.
|
||||
@@ -1071,8 +1092,8 @@ As you will see from the confusion matrix below, XGBoots does an excellent job o
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -1085,11 +1106,11 @@ xg_clf.fit(X_train_scaled,y_train)
|
||||
|
||||
y_test = xg_clf.predict(X_test_scaled)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(xg_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(xg_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = xg_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #CD5555">"xdclassiffierconfusion"</span>)
|
||||
plt.show()
|
||||
y_probas = xg_clf.predict_proba(X_test_scaled)
|
||||
|
||||
@@ -35,64 +35,66 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -134,12 +136,32 @@ 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 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 31, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec0">Random forests </h2>
|
||||
<h2 id="___sec0">Overview of week 45 </h2>
|
||||
|
||||
<ul>
|
||||
<li> "Thursday: Wrapping up from last week. Bagging and Random forests.</li>
|
||||
<li> "Friday: Boosting and gradient boosting</li>
|
||||
</ul>
|
||||
|
||||
Geron's chapter 7. See also lecture from <a href="https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf" target="_blank">STK-IN4300, lecture 7</a>. Chapter 9.2 of Hastie et al contains also a good discussion.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Thursday </h2>
|
||||
|
||||
<p>
|
||||
Bagging, voting and random forests.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec2">Random forests </h2>
|
||||
|
||||
<p>
|
||||
Random forests provide an improvement over bagged trees by way of a
|
||||
@@ -183,7 +205,7 @@ this setting.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Random Forest Algorithm </h2>
|
||||
<h2 id="___sec3">Random Forest Algorithm </h2>
|
||||
The algorithm described here can be applied to both classification and regression problems.
|
||||
|
||||
<p>
|
||||
@@ -209,7 +231,7 @@ We will grow of forest of say \( B \) trees.
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec2">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<h2 id="___sec4">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -225,20 +247,20 @@ We will grow of forest of say \( B \) trees.
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22"># Logistic Regression</span>
|
||||
logreg = LogisticRegression(solver=<span style="color: #CD5555">'lbfgs'</span>)
|
||||
logreg.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Logistic Regression: {:.2f}"</span>.format(logreg.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Logistic Regression: {:.2f}"</span>.format(logreg.score(X_test,y_test)))
|
||||
<span style="color: #228B22"># Support vector machine</span>
|
||||
svm = SVC(gamma=<span style="color: #CD5555">'auto'</span>, C=<span style="color: #B452CD">100</span>)
|
||||
svm.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with SVM: {:.2f}"</span>.format(svm.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with SVM: {:.2f}"</span>.format(svm.score(X_test,y_test)))
|
||||
<span style="color: #228B22"># Decision Trees</span>
|
||||
deep_tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #658b00">None</span>)
|
||||
deep_tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #8B008B; font-weight: bold">None</span>)
|
||||
deep_tree_clf.fit(X_train, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees: {:.2f}"</span>.format(deep_tree_clf.score(X_test,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees: {:.2f}"</span>.format(deep_tree_clf.score(X_test,y_test)))
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -247,13 +269,13 @@ X_train_scaled = scaler.transform(X_train)
|
||||
X_test_scaled = scaler.transform(X_test)
|
||||
<span style="color: #228B22"># Logistic Regression</span>
|
||||
logreg.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #228B22"># Support Vector Machine</span>
|
||||
svm.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy SVM with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy SVM with scaled data: {:.2f}"</span>.format(logreg.score(X_test_scaled,y_test)))
|
||||
<span style="color: #228B22"># Decision Trees</span>
|
||||
deep_tree_clf.fit(X_train_scaled, y_train)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span>.format(deep_tree_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span>.format(deep_tree_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> RandomForestClassifier
|
||||
@@ -265,13 +287,13 @@ Random_Forest_model = RandomForestClassifier(n_estimators=<span style="color: #B
|
||||
Random_Forest_model.fit(X_train_scaled, y_train)
|
||||
<span style="color: #228B22">#Cross validation</span>
|
||||
accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=<span style="color: #B452CD">10</span>)[<span style="color: #CD5555">'test_score'</span>]
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(Random_Forest_model.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(accuracy)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(Random_Forest_model.score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = Random_Forest_model.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
plt.show()
|
||||
y_probas = Random_Forest_model.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
@@ -282,13 +304,13 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">Compare Bagging on Trees with Random Forests </h2>
|
||||
<h2 id="___sec5">Compare Bagging on Trees with Random Forests </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span>bag_clf = BaggingClassifier(
|
||||
DecisionTreeClassifier(splitter=<span style="color: #CD5555">"random"</span>, max_leaf_nodes=<span style="color: #B452CD">16</span>, random_state=<span style="color: #B452CD">42</span>),
|
||||
n_estimators=<span style="color: #B452CD">500</span>, max_samples=<span style="color: #B452CD">1.0</span>, bootstrap=<span style="color: #658b00">True</span>, n_jobs=-<span style="color: #B452CD">1</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
n_estimators=<span style="color: #B452CD">500</span>, max_samples=<span style="color: #B452CD">1.0</span>, bootstrap=<span style="color: #8B008B; font-weight: bold">True</span>, n_jobs=-<span style="color: #B452CD">1</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
@@ -304,7 +326,7 @@ np.sum(y_pred == y_pred_rf) / <span style="color: #658b00">len</span>(y_pred)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec4">Boosting, a Bird's Eye View </h2>
|
||||
<h2 id="___sec6">Boosting, a Bird's Eye View </h2>
|
||||
|
||||
<p>
|
||||
The basic idea is to combine weak classifiers in order to create a good
|
||||
@@ -321,7 +343,7 @@ them with a factor.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
<h2 id="___sec7">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
Boosting is a way of fitting an additive expansion in a set of
|
||||
@@ -373,7 +395,7 @@ In iterative fitting or additive modeling, we minimize the cost function with re
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
<h2 id="___sec8">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
|
||||
<p>
|
||||
The way we proceed is as follows (here we specialize to the squared-error cost function)
|
||||
@@ -398,7 +420,7 @@ at the internal nodes, and the predictions at the terminal nodes.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec7">Squared-Error Example and Iterative Fitting </h2>
|
||||
<h2 id="___sec9">Squared-Error Example and Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.
|
||||
@@ -446,7 +468,7 @@ The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec8">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
<h2 id="___sec10">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
Let us consider a binary classification problem with two outcomes \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
@@ -481,7 +503,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec9">Adaptive Boosting, AdaBoost </h2>
|
||||
<h2 id="___sec11">Adaptive Boosting, AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
In our iterative procedure we define thus
|
||||
@@ -509,7 +531,7 @@ where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec10">Building up AdaBoost </h2>
|
||||
<h2 id="___sec12">Building up AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
First, for any \( \beta > 0 \), we optimize \( G \) by setting
|
||||
@@ -553,7 +575,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
<h2 id="___sec13">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
|
||||
<p>
|
||||
The algorithm here is rather straightforward. Assume that our weak
|
||||
@@ -575,7 +597,7 @@ where the function \( I() \) is one if we misclassify and zero if we classify co
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Basic Steps of AdaBoost </h2>
|
||||
<h2 id="___sec14">Basic Steps of AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
With the above definitions we are now ready to set up the algorithm for AdaBoost.
|
||||
@@ -615,7 +637,7 @@ observations that are missed in the previous iterations.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">AdaBoost Examples </h2>
|
||||
<h2 id="___sec15">AdaBoost Examples </h2>
|
||||
|
||||
<p>
|
||||
Using <b>Scikit-Learn</b> it is easy to apply the adaptive boosting algorithm, as done here.
|
||||
@@ -637,7 +659,7 @@ ada_clf = AdaBoostClassifier(
|
||||
algorithm=<span style="color: #CD5555">"SAMME.R"</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
|
||||
ada_clf.fit(X_train_scaled, y_train)
|
||||
y_pred = ada_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
plt.show()
|
||||
y_probas = ada_clf.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
@@ -648,7 +670,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">AdaBoost for Regression </h2>
|
||||
<h2 id="___sec16">AdaBoost for Regression </h2>
|
||||
|
||||
<p>
|
||||
Here we present <a href="https://pdfs.semanticscholar.org/8d49/e2dedb817f2c3330e74b63c5fc86d2399ce3.pdf" target="_blank">Drucker's AdaBoost</a> tailored for regression.
|
||||
@@ -676,7 +698,7 @@ Start by selecting a set of training data \( n \) and assign to each entry a wei
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
<h2 id="___sec17">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
Gradient boosting is again a similar technique to Adaptive boosting,
|
||||
@@ -691,7 +713,7 @@ function was the least squares function.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">The Squared-Error again! Steepest Descent </h2>
|
||||
<h2 id="___sec18">The Squared-Error again! Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
We start again with our cost function \( {\cal C}(\boldsymbol{y}m\boldsymbol{f})=\sum_{i=0}^{n-1}{\cal L}(y_i, f(x_i)) \) where we want to minimize
|
||||
@@ -726,7 +748,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">Steepest Descent Example </h2>
|
||||
<h2 id="___sec19">Steepest Descent Example </h2>
|
||||
|
||||
<p>
|
||||
Optimizing with respect to \( \rho \) we obtain (taking the derivative) that \( \rho_1 = -1/2 \). We have then that
|
||||
@@ -744,7 +766,7 @@ and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \(
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec18">Gradient Boosting, algorithm </h2>
|
||||
<h2 id="___sec20">Gradient Boosting, algorithm </h2>
|
||||
|
||||
<p>
|
||||
Suppose we have a cost function \( C(f)=\sum_{i=0}^{n-1}L(y_i, f(x_i)) \) where \( y_i \) is our target and \( f(x_i) \) the function which is meant to model \( y_i \). The above cost function could be our standard squared-error function
|
||||
@@ -770,7 +792,7 @@ The way we proceed in an iterative fashion is to
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec19">Gradient Boosting Example, Regression </h2>
|
||||
<h2 id="___sec21">Gradient Boosting Example, Regression </h2>
|
||||
|
||||
<p>
|
||||
We discuss here the difference between the steepest descent approach and gradient boosting by repeating our simple regression example above.
|
||||
@@ -778,7 +800,7 @@ We discuss here the difference between the steepest descent approach and gradien
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec20">Gradient Boosting, Examples of Regression </h2>
|
||||
<h2 id="___sec22">Gradient Boosting, Examples of Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -815,11 +837,11 @@ X_test_scaled = scaler.transform(X_test)
|
||||
error[degree] = np.mean( np.mean((y_test - y_pred)**<span style="color: #B452CD">2</span>) )
|
||||
bias[degree] = np.mean( (y_test - np.mean(y_pred))**<span style="color: #B452CD">2</span> )
|
||||
variance[degree] = np.mean( np.var(y_pred) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdegree-<span style="color: #B452CD">1</span>)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'Error'</span>)
|
||||
@@ -832,7 +854,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Gradient Boosting, Classification Example </h2>
|
||||
<h2 id="___sec23">Gradient Boosting, Classification Example </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -848,8 +870,8 @@ plt.show()
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -861,12 +883,12 @@ gd_clf = GradientBoostingClassifier(max_depth=<span style="color: #B452CD">3</sp
|
||||
gd_clf.fit(X_train_scaled, y_train)
|
||||
<span style="color: #228B22">#Cross validation</span>
|
||||
accuracy = cross_validate(gd_clf,X_test_scaled,y_test,cv=<span style="color: #B452CD">10</span>)[<span style="color: #CD5555">'test_score'</span>]
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(gd_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(accuracy)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(gd_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = gd_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #CD5555">"gdclassiffierconfusion"</span>)
|
||||
plt.show()
|
||||
y_probas = gd_clf.predict_proba(X_test_scaled)
|
||||
@@ -880,7 +902,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">XGBoost: Extreme Gradient Boosting </h2>
|
||||
<h2 id="___sec24">XGBoost: Extreme Gradient Boosting </h2>
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/dmlc/xgboost" target="_blank">XGBoost</a> or Extreme Gradient
|
||||
@@ -901,7 +923,7 @@ It is now the algorithm which wins essentially all ML competitions!!!
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec23">Regression Case </h2>
|
||||
<h2 id="___sec25">Regression Case </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -940,11 +962,11 @@ X_test_scaled = scaler.transform(X_test)
|
||||
error[degree] = np.mean( np.mean((y_test - y_pred)**<span style="color: #B452CD">2</span>) )
|
||||
bias[degree] = np.mean( (y_test - np.mean(y_pred))**<span style="color: #B452CD">2</span> )
|
||||
variance[degree] = np.mean( np.var(y_pred) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Max depth:'</span>, degree)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Error:'</span>, error[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdegree-<span style="color: #B452CD">1</span>)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'Error'</span>)
|
||||
@@ -956,7 +978,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec24">Xgboost on the Cancer Data </h2>
|
||||
<h2 id="___sec26">Xgboost on the Cancer Data </h2>
|
||||
|
||||
<p>
|
||||
As you will see from the confusion matrix below, XGBoots does an excellent job on the Wisconsin cancer data and outperforms essentially all agorithms we have discussed till now.
|
||||
@@ -975,8 +997,8 @@ As you will see from the confusion matrix below, XGBoots does an excellent job o
|
||||
cancer = load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_test.shape)
|
||||
<span style="color: #658b00">print</span>(X_train.shape)
|
||||
<span style="color: #658b00">print</span>(X_test.shape)
|
||||
<span style="color: #228B22">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler = StandardScaler()
|
||||
@@ -989,11 +1011,11 @@ xg_clf.fit(X_train_scaled,y_train)
|
||||
|
||||
y_test = xg_clf.predict(X_test_scaled)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(xg_clf.score(X_test_scaled,y_test)))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span>.format(xg_clf.score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">scikitplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skplt</span>
|
||||
y_pred = xg_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #658b00">True</span>)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=<span style="color: #8B008B; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #CD5555">"xdclassiffierconfusion"</span>)
|
||||
plt.show()
|
||||
y_probas = xg_clf.predict_proba(X_test_scaled)
|
||||
|
||||
+106
-84
@@ -40,64 +40,66 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Random forests', 2, None, '___sec0'),
|
||||
('Random Forest Algorithm', 2, None, '___sec1'),
|
||||
'sections': [('Overview of week 45', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Random forests', 2, None, '___sec2'),
|
||||
('Random Forest Algorithm', 2, None, '___sec3'),
|
||||
('Random Forests Compared with other Methods on the Cancer Data',
|
||||
2,
|
||||
None,
|
||||
'___sec2'),
|
||||
'___sec4'),
|
||||
('Compare Bagging on Trees with Random Forests',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec4'),
|
||||
'___sec5'),
|
||||
("Boosting, a Bird's Eye View", 2, None, '___sec6'),
|
||||
('What is boosting? Additive Modelling/Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
'___sec7'),
|
||||
('Iterative Fitting, Regression and Squared-error Cost Function',
|
||||
2,
|
||||
None,
|
||||
'___sec6'),
|
||||
'___sec8'),
|
||||
('Squared-Error Example and Iterative Fitting',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
'___sec9'),
|
||||
('Iterative Fitting, Classification and AdaBoost',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec9'),
|
||||
('Building up AdaBoost', 2, None, '___sec10'),
|
||||
'___sec10'),
|
||||
('Adaptive Boosting, AdaBoost', 2, None, '___sec11'),
|
||||
('Building up AdaBoost', 2, None, '___sec12'),
|
||||
('Adaptive boosting: AdaBoost, Basic Algorithm',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec12'),
|
||||
('AdaBoost Examples', 2, None, '___sec13'),
|
||||
('AdaBoost for Regression', 2, None, '___sec14'),
|
||||
'___sec13'),
|
||||
('Basic Steps of AdaBoost', 2, None, '___sec14'),
|
||||
('AdaBoost Examples', 2, None, '___sec15'),
|
||||
('AdaBoost for Regression', 2, None, '___sec16'),
|
||||
('Gradient boosting: Basics with Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec15'),
|
||||
'___sec17'),
|
||||
('The Squared-Error again! Steepest Descent',
|
||||
2,
|
||||
None,
|
||||
'___sec16'),
|
||||
('Steepest Descent Example', 2, None, '___sec17'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec18'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec19'),
|
||||
'___sec18'),
|
||||
('Steepest Descent Example', 2, None, '___sec19'),
|
||||
('Gradient Boosting, algorithm', 2, None, '___sec20'),
|
||||
('Gradient Boosting Example, Regression', 2, None, '___sec21'),
|
||||
('Gradient Boosting, Examples of Regression',
|
||||
2,
|
||||
None,
|
||||
'___sec20'),
|
||||
'___sec22'),
|
||||
('Gradient Boosting, Classification Example',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec22'),
|
||||
('Regression Case', 2, None, '___sec23'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec24')]}
|
||||
'___sec23'),
|
||||
('XGBoost: Extreme Gradient Boosting', 2, None, '___sec24'),
|
||||
('Regression Case', 2, None, '___sec25'),
|
||||
('Xgboost on the Cancer Data', 2, None, '___sec26')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -139,12 +141,32 @@ 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 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 31, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec0">Random forests </h2>
|
||||
<h2 id="___sec0">Overview of week 45 </h2>
|
||||
|
||||
<ul>
|
||||
<li> "Thursday: Wrapping up from last week. Bagging and Random forests.</li>
|
||||
<li> "Friday: Boosting and gradient boosting</li>
|
||||
</ul>
|
||||
|
||||
Geron's chapter 7. See also lecture from <a href="https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf" target="_blank">STK-IN4300, lecture 7</a>. Chapter 9.2 of Hastie et al contains also a good discussion.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Thursday </h2>
|
||||
|
||||
<p>
|
||||
Bagging, voting and random forests.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec2">Random forests </h2>
|
||||
|
||||
<p>
|
||||
Random forests provide an improvement over bagged trees by way of a
|
||||
@@ -188,7 +210,7 @@ this setting.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Random Forest Algorithm </h2>
|
||||
<h2 id="___sec3">Random Forest Algorithm </h2>
|
||||
The algorithm described here can be applied to both classification and regression problems.
|
||||
|
||||
<p>
|
||||
@@ -214,7 +236,7 @@ We will grow of forest of say \( B \) trees.
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec2">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<h2 id="___sec4">Random Forests Compared with other Methods on the Cancer Data </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -230,20 +252,20 @@ We will grow of forest of say \( B \) trees.
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">'lbfgs'</span>)
|
||||
logreg<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Logistic Regression: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Logistic Regression: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support vector machine</span>
|
||||
svm <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">'auto'</span>, C<span style="color: #666666">=100</span>)
|
||||
svm<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with SVM: {:.2f}"</span><span style="color: #666666">.</span>format(svm<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with SVM: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(svm<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=</span><span style="color: #008000">None</span>)
|
||||
deep_tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">None</span>)
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees: {:.2f}"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test,y_test)))
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
@@ -252,13 +274,13 @@ X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
<span style="color: #408080; font-style: italic"># Logistic Regression</span>
|
||||
logreg<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy Logistic Regression with scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy Logistic Regression with scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Support Vector Machine</span>
|
||||
svm<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy SVM with scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy SVM with scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(logreg<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #408080; font-style: italic"># Decision Trees</span>
|
||||
deep_tree_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Decision Trees and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
|
||||
@@ -270,13 +292,13 @@ Random_Forest_model <span style="color: #666666">=</span> RandomForestClassifier
|
||||
Random_Forest_model<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(Random_Forest_model,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(Random_Forest_model<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(accuracy)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(Random_Forest_model<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> Random_Forest_model<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
@@ -287,13 +309,13 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">Compare Bagging on Trees with Random Forests </h2>
|
||||
<h2 id="___sec5">Compare Bagging on Trees with Random Forests </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf <span style="color: #666666">=</span> BaggingClassifier(
|
||||
DecisionTreeClassifier(splitter<span style="color: #666666">=</span><span style="color: #BA2121">"random"</span>, max_leaf_nodes<span style="color: #666666">=16</span>, random_state<span style="color: #666666">=42</span>),
|
||||
n_estimators<span style="color: #666666">=500</span>, max_samples<span style="color: #666666">=1.0</span>, bootstrap<span style="color: #666666">=</span><span style="color: #008000">True</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
n_estimators<span style="color: #666666">=500</span>, max_samples<span style="color: #666666">=1.0</span>, bootstrap<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
@@ -309,7 +331,7 @@ np<span style="color: #666666">.</span>sum(y_pred <span style="color: #666666">=
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec4">Boosting, a Bird's Eye View </h2>
|
||||
<h2 id="___sec6">Boosting, a Bird's Eye View </h2>
|
||||
|
||||
<p>
|
||||
The basic idea is to combine weak classifiers in order to create a good
|
||||
@@ -326,7 +348,7 @@ them with a factor.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
<h2 id="___sec7">What is boosting? Additive Modelling/Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
Boosting is a way of fitting an additive expansion in a set of
|
||||
@@ -378,7 +400,7 @@ In iterative fitting or additive modeling, we minimize the cost function with re
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
<h2 id="___sec8">Iterative Fitting, Regression and Squared-error Cost Function </h2>
|
||||
|
||||
<p>
|
||||
The way we proceed is as follows (here we specialize to the squared-error cost function)
|
||||
@@ -403,7 +425,7 @@ at the internal nodes, and the predictions at the terminal nodes.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec7">Squared-Error Example and Iterative Fitting </h2>
|
||||
<h2 id="___sec9">Squared-Error Example and Iterative Fitting </h2>
|
||||
|
||||
<p>
|
||||
To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.
|
||||
@@ -451,7 +473,7 @@ The solution to these two equations gives us in turn \( \beta_1 \) and \( \gamma
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec8">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
<h2 id="___sec10">Iterative Fitting, Classification and AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
Let us consider a binary classification problem with two outcomes \( y_i \in \{-1,1\} \) and \( i=0,1,2,\dots,n-1 \) as our set of
|
||||
@@ -486,7 +508,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec9">Adaptive Boosting, AdaBoost </h2>
|
||||
<h2 id="___sec11">Adaptive Boosting, AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
In our iterative procedure we define thus
|
||||
@@ -514,7 +536,7 @@ where we have defined \( w_i^m= \exp{(-y_if_{m-1}(x_i))} \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec10">Building up AdaBoost </h2>
|
||||
<h2 id="___sec12">Building up AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
First, for any \( \beta > 0 \), we optimize \( G \) by setting
|
||||
@@ -558,7 +580,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
<h2 id="___sec13">Adaptive boosting: AdaBoost, Basic Algorithm </h2>
|
||||
|
||||
<p>
|
||||
The algorithm here is rather straightforward. Assume that our weak
|
||||
@@ -580,7 +602,7 @@ where the function \( I() \) is one if we misclassify and zero if we classify co
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Basic Steps of AdaBoost </h2>
|
||||
<h2 id="___sec14">Basic Steps of AdaBoost </h2>
|
||||
|
||||
<p>
|
||||
With the above definitions we are now ready to set up the algorithm for AdaBoost.
|
||||
@@ -620,7 +642,7 @@ observations that are missed in the previous iterations.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">AdaBoost Examples </h2>
|
||||
<h2 id="___sec15">AdaBoost Examples </h2>
|
||||
|
||||
<p>
|
||||
Using <b>Scikit-Learn</b> it is easy to apply the adaptive boosting algorithm, as done here.
|
||||
@@ -642,7 +664,7 @@ ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
|
||||
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">"SAMME.R"</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
|
||||
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
|
||||
@@ -653,7 +675,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">AdaBoost for Regression </h2>
|
||||
<h2 id="___sec16">AdaBoost for Regression </h2>
|
||||
|
||||
<p>
|
||||
Here we present <a href="https://pdfs.semanticscholar.org/8d49/e2dedb817f2c3330e74b63c5fc86d2399ce3.pdf" target="_blank">Drucker's AdaBoost</a> tailored for regression.
|
||||
@@ -681,7 +703,7 @@ Start by selecting a set of training data \( n \) and assign to each entry a wei
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
<h2 id="___sec17">Gradient boosting: Basics with Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
Gradient boosting is again a similar technique to Adaptive boosting,
|
||||
@@ -696,7 +718,7 @@ function was the least squares function.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">The Squared-Error again! Steepest Descent </h2>
|
||||
<h2 id="___sec18">The Squared-Error again! Steepest Descent </h2>
|
||||
|
||||
<p>
|
||||
We start again with our cost function \( {\cal C}(\boldsymbol{y}m\boldsymbol{f})=\sum_{i=0}^{n-1}{\cal L}(y_i, f(x_i)) \) where we want to minimize
|
||||
@@ -731,7 +753,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">Steepest Descent Example </h2>
|
||||
<h2 id="___sec19">Steepest Descent Example </h2>
|
||||
|
||||
<p>
|
||||
Optimizing with respect to \( \rho \) we obtain (taking the derivative) that \( \rho_1 = -1/2 \). We have then that
|
||||
@@ -749,7 +771,7 @@ and find a new value for \( \rho_2=-1/2 \) and continue till we have reached \(
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec18">Gradient Boosting, algorithm </h2>
|
||||
<h2 id="___sec20">Gradient Boosting, algorithm </h2>
|
||||
|
||||
<p>
|
||||
Suppose we have a cost function \( C(f)=\sum_{i=0}^{n-1}L(y_i, f(x_i)) \) where \( y_i \) is our target and \( f(x_i) \) the function which is meant to model \( y_i \). The above cost function could be our standard squared-error function
|
||||
@@ -775,7 +797,7 @@ The way we proceed in an iterative fashion is to
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec19">Gradient Boosting Example, Regression </h2>
|
||||
<h2 id="___sec21">Gradient Boosting Example, Regression </h2>
|
||||
|
||||
<p>
|
||||
We discuss here the difference between the steepest descent approach and gradient boosting by repeating our simple regression example above.
|
||||
@@ -783,7 +805,7 @@ We discuss here the difference between the steepest descent approach and gradien
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec20">Gradient Boosting, Examples of Regression </h2>
|
||||
<h2 id="___sec22">Gradient Boosting, Examples of Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -820,11 +842,11 @@ X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #6
|
||||
error[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>) )
|
||||
bias[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred))<span style="color: #666666">**2</span> )
|
||||
variance[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred) )
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'{} >= {} + {} = {}'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdegree<span style="color: #666666">-1</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'Error'</span>)
|
||||
@@ -837,7 +859,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Gradient Boosting, Classification Example </h2>
|
||||
<h2 id="___sec23">Gradient Boosting, Classification Example </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -853,8 +875,8 @@ plt<span style="color: #666666">.</span>show()
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
@@ -866,12 +888,12 @@ gd_clf <span style="color: #666666">=</span> GradientBoostingClassifier(max_dept
|
||||
gd_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<span style="color: #408080; font-style: italic">#Cross validation</span>
|
||||
accuracy <span style="color: #666666">=</span> cross_validate(gd_clf,X_test_scaled,y_test,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">'test_score'</span>]
|
||||
<span style="color: #008000; font-weight: bold">print</span>(accuracy)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(gd_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(accuracy)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(gd_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #BA2121">"gdclassiffierconfusion"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> gd_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
@@ -885,7 +907,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">XGBoost: Extreme Gradient Boosting </h2>
|
||||
<h2 id="___sec24">XGBoost: Extreme Gradient Boosting </h2>
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/dmlc/xgboost" target="_blank">XGBoost</a> or Extreme Gradient
|
||||
@@ -906,7 +928,7 @@ It is now the algorithm which wins essentially all ML competitions!!!
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec23">Regression Case </h2>
|
||||
<h2 id="___sec25">Regression Case </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -945,11 +967,11 @@ X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #6
|
||||
error[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>) )
|
||||
bias[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred))<span style="color: #666666">**2</span> )
|
||||
variance[degree] <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred) )
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">'{} >= {} + {} = {}'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Max depth:'</span>, degree)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Error:'</span>, error[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdegree<span style="color: #666666">-1</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'Error'</span>)
|
||||
@@ -961,7 +983,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec24">Xgboost on the Cancer Data </h2>
|
||||
<h2 id="___sec26">Xgboost on the Cancer Data </h2>
|
||||
|
||||
<p>
|
||||
As you will see from the confusion matrix below, XGBoots does an excellent job on the Wisconsin cancer data and outperforms essentially all agorithms we have discussed till now.
|
||||
@@ -980,8 +1002,8 @@ As you will see from the confusion matrix below, XGBoots does an excellent job o
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #008000">print</span>(X_test<span style="color: #666666">.</span>shape)
|
||||
<span style="color: #408080; font-style: italic">#now scale the data</span>
|
||||
<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> StandardScaler
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
@@ -994,11 +1016,11 @@ xg_clf<span style="color: #666666">.</span>fit(X_train_scaled,y_train)
|
||||
|
||||
y_test <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: {:.2f}"</span><span style="color: #666666">.</span>format(xg_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test set accuracy with Random Forests and scaled data: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(xg_clf<span style="color: #666666">.</span>score(X_test_scaled,y_test)))
|
||||
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scikitplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skplt</span>
|
||||
y_pred <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
|
||||
save_fig(<span style="color: #BA2121">"xdclassiffierconfusion"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
y_probas <span style="color: #666666">=</span> xg_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
|
||||
|
||||
Binary file not shown.
@@ -10,12 +10,24 @@
|
||||
"<!-- 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 16, 2020**\n",
|
||||
"Date: **Oct 31, 2020**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Overview of week 45\n",
|
||||
"\n",
|
||||
"* \"Thursday: Wrapping up from last week. Bagging and Random forests.\n",
|
||||
"\n",
|
||||
"* \"Friday: Boosting and gradient boosting\n",
|
||||
"\n",
|
||||
"Geron's chapter 7. See also lecture from [STK-IN4300, lecture 7](https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf). Chapter 9.2 of Hastie et al contains also a good discussion.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Thursday\n",
|
||||
"\n",
|
||||
"Bagging, voting and random forests.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Random forests\n",
|
||||
@@ -1208,5 +1220,5 @@
|
||||
],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
||||
@@ -2,6 +2,20 @@ TITLE: Week 45: Random Forests and Boosting
|
||||
AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
|
||||
DATE: today
|
||||
|
||||
!split
|
||||
===== Overview of week 45 =====
|
||||
|
||||
* "Thursday: Wrapping up from last week. Bagging and Random forests.
|
||||
* "Friday: Boosting and gradient boosting
|
||||
|
||||
|
||||
Geron's chapter 7. See also lecture from "STK-IN4300, lecture 7":"https://www.uio.no/studier/emner/matnat/math/STK-IN4300/h20/slides/lecture_7.pdf". Chapter 9.2 of Hastie et al contains also a good discussion.
|
||||
|
||||
|
||||
!split
|
||||
===== Thursday =====
|
||||
|
||||
Bagging, voting and random forests.
|
||||
|
||||
|
||||
!split
|
||||
|
||||
Reference in New Issue
Block a user