added more on trees
This commit is contained in:
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -220,7 +229,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>Oct 26, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 27, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -244,7 +253,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs008.html">9</a></li>
|
||||
<li><a href="._week44-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -227,7 +236,7 @@ Geron's chapter 6 covers decision trees while ensemble models, voting and baggin
|
||||
<li><a href="._week44-bs009.html">10</a></li>
|
||||
<li><a href="._week44-bs010.html">11</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -224,7 +233,7 @@ Overview video, aims and motivations.
|
||||
<li><a href="._week44-bs010.html">11</a></li>
|
||||
<li><a href="._week44-bs011.html">12</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs003.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -228,18 +237,6 @@ to be the most informative ones. The process of finding the <b>most
|
||||
informative</b> feature is done until we accomplish a stopping criteria
|
||||
where we then finally end up in so called <b>leaf nodes</b>.
|
||||
|
||||
<p>
|
||||
A decision tree is typically divided into a <b>root node</b>, the <b>interior nodes</b>,
|
||||
and the final <b>leaf nodes</b> or just <b>leaves</b>. These entities are then connected by so-called <b>branches</b>.
|
||||
|
||||
<p>
|
||||
The leaf nodes
|
||||
contain the predictions we will make for new query instances presented
|
||||
to our trained model. This is possible since the model has
|
||||
learned the underlying structure of the training data and hence can,
|
||||
given some assumptions, make predictions about the target feature value
|
||||
(class) of unseen query instances.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -259,7 +256,7 @@ given some assumptions, make predictions about the target feature value
|
||||
<li><a href="._week44-bs011.html">12</a></li>
|
||||
<li><a href="._week44-bs012.html">13</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs004.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,13 +210,19 @@ MathJax.Hub.Config({
|
||||
<a name="part0004"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec3" class="anchor">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
<h2 id="___sec3" class="anchor">Basics of a tree </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/cancer.png" align="bottom" width=600></p></center><br /><br />
|
||||
A decision tree is typically divided into a <b>root node</b>, the <b>interior nodes</b>,
|
||||
and the final <b>leaf nodes</b> or just <b>leaves</b>. These entities are then connected by so-called <b>branches</b>.
|
||||
|
||||
<p>
|
||||
This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using <b>Scikit-Learn</b>'s decision tree classifier. Here we have used the so-called <b>gini</b> index (see below) to split the various branches.
|
||||
The leaf nodes
|
||||
contain the predictions we will make for new query instances presented
|
||||
to our trained model. This is possible since the model has
|
||||
learned the underlying structure of the training data and hence can,
|
||||
given some assumptions, make predictions about the target feature value
|
||||
(class) of unseen query instances.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -229,7 +244,7 @@ This tree was produced using the Wisconsin cancer data (discussed here as well,
|
||||
<li><a href="._week44-bs012.html">13</a></li>
|
||||
<li><a href="._week44-bs013.html">14</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs005.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,20 +210,10 @@ MathJax.Hub.Config({
|
||||
<a name="part0005"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec4" class="anchor">General Features </h2>
|
||||
<h2 id="___sec4" class="anchor">A Sketch of a Tree, Regression problem </h2>
|
||||
|
||||
<p>
|
||||
The overarching approach to decision trees is a top-down approach.
|
||||
|
||||
<ul>
|
||||
<li> A leaf provides the classification of a given instance.</li>
|
||||
<li> A node specifies a test of some attribute of the instance.</li>
|
||||
<li> A branch corresponds to a possible values of an attribute.</li>
|
||||
<li> An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.</li>
|
||||
</ul>
|
||||
|
||||
This process is then repeated for the subtree rooted at the new
|
||||
node.
|
||||
<!-- FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -237,7 +236,7 @@ node.
|
||||
<li><a href="._week44-bs013.html">14</a></li>
|
||||
<li><a href="._week44-bs014.html">15</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs006.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,20 +210,10 @@ MathJax.Hub.Config({
|
||||
<a name="part0006"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec5" class="anchor">How do we set it up? </h2>
|
||||
<h2 id="___sec5" class="anchor">A Sketch of a Tree, Classification problem </h2>
|
||||
|
||||
<p>
|
||||
In simplified terms, the process of training a decision tree and
|
||||
predicting the target features of query instances is as follows:
|
||||
|
||||
<ol>
|
||||
<li> Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature</li>
|
||||
<li> Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process</li>
|
||||
<li> Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the <em>predictions</em> we want to make for new query instances</li>
|
||||
<li> Show query instances to the tree and run down the tree until we arrive at leaf nodes</li>
|
||||
</ol>
|
||||
|
||||
Then we are essentially done!
|
||||
<!-- FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -238,7 +237,7 @@ Then we are essentially done!
|
||||
<li><a href="._week44-bs014.html">15</a></li>
|
||||
<li><a href="._week44-bs015.html">16</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs007.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,99 +210,14 @@ MathJax.Hub.Config({
|
||||
<a name="part0007"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec6" class="anchor">Decision trees and Regression </h2>
|
||||
<h2 id="___sec6" class="anchor">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/cancer.png" align="bottom" width=600></p></center><br /><br />
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
<p>
|
||||
This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using <b>Scikit-Learn</b>'s decision tree classifier. Here we have used the so-called <b>gini</b> index (see below) to split the various branches.
|
||||
|
||||
steps<span style="color: #666666">=250</span>
|
||||
|
||||
distance<span style="color: #666666">=0</span>
|
||||
x<span style="color: #666666">=0</span>
|
||||
distance_list<span style="color: #666666">=</span>[]
|
||||
steps_list<span style="color: #666666">=</span>[]
|
||||
<span style="color: #008000; font-weight: bold">while</span> x<span style="color: #666666"><</span>steps:
|
||||
distance<span style="color: #666666">+=</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randint(<span style="color: #666666">-1</span>,<span style="color: #666666">2</span>)
|
||||
distance_list<span style="color: #666666">.</span>append(distance)
|
||||
x<span style="color: #666666">+=1</span>
|
||||
steps_list<span style="color: #666666">.</span>append(x)
|
||||
plt<span style="color: #666666">.</span>plot(steps_list,distance_list, color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Random Walk Data"</span>)
|
||||
|
||||
steps_list<span style="color: #666666">=</span>np<span style="color: #666666">.</span>asarray(steps_list)
|
||||
distance_list<span style="color: #666666">=</span>np<span style="color: #666666">.</span>asarray(distance_list)
|
||||
|
||||
X<span style="color: #666666">=</span>steps_list[:,np<span style="color: #666666">.</span>newaxis]
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Polynomial fits</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Degree 2</span>
|
||||
poly_features<span style="color: #666666">=</span>PolynomialFeatures(degree<span style="color: #666666">=2</span>, include_bias<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
X_poly<span style="color: #666666">=</span>poly_features<span style="color: #666666">.</span>fit_transform(X)
|
||||
|
||||
lin_reg<span style="color: #666666">=</span>LinearRegression()
|
||||
poly_fit<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>fit(X_poly,distance_list)
|
||||
b<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>coef_
|
||||
c<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>intercept_
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"2nd degree coefficients:"</span>)
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"zero power: "</span>,c)
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"first power: "</span>, b[<span style="color: #666666">0</span>])
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"second power: "</span>,b[<span style="color: #666666">1</span>])
|
||||
|
||||
z <span style="color: #666666">=</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">0</span>, steps, <span style="color: #666666">.01</span>)
|
||||
z_mod<span style="color: #666666">=</span>b[<span style="color: #666666">1</span>]<span style="color: #666666">*</span>z<span style="color: #666666">**2+</span>b[<span style="color: #666666">0</span>]<span style="color: #666666">*</span>z<span style="color: #666666">+</span>c
|
||||
|
||||
fit_mod<span style="color: #666666">=</span>b[<span style="color: #666666">1</span>]<span style="color: #666666">*</span>X<span style="color: #666666">**2+</span>b[<span style="color: #666666">0</span>]<span style="color: #666666">*</span>X<span style="color: #666666">+</span>c
|
||||
plt<span style="color: #666666">.</span>plot(z, z_mod, color<span style="color: #666666">=</span><span style="color: #BA2121">'r'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"2nd Degree Fit"</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Polynomial Regression"</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Steps"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Distance"</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Degree 10</span>
|
||||
poly_features10<span style="color: #666666">=</span>PolynomialFeatures(degree<span style="color: #666666">=10</span>, include_bias<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
X_poly10<span style="color: #666666">=</span>poly_features10<span style="color: #666666">.</span>fit_transform(X)
|
||||
|
||||
poly_fit10<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>fit(X_poly10,distance_list)
|
||||
|
||||
y_plot<span style="color: #666666">=</span>poly_fit10<span style="color: #666666">.</span>predict(X_poly10)
|
||||
plt<span style="color: #666666">.</span>plot(X, y_plot, color<span style="color: #666666">=</span><span style="color: #BA2121">'black'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"10th Degree Fit"</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Decision Tree Regression</span>
|
||||
<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> DecisionTreeRegressor
|
||||
regr_1<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=2</span>)
|
||||
regr_2<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=5</span>)
|
||||
regr_3<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=7</span>)
|
||||
regr_1<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
regr_2<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
regr_3<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
|
||||
X_test <span style="color: #666666">=</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">0.0</span>, steps, <span style="color: #666666">0.01</span>)[:, np<span style="color: #666666">.</span>newaxis]
|
||||
y_1 <span style="color: #666666">=</span> regr_1<span style="color: #666666">.</span>predict(X_test)
|
||||
y_2 <span style="color: #666666">=</span> regr_2<span style="color: #666666">.</span>predict(X_test)
|
||||
y_3<span style="color: #666666">=</span>regr_3<span style="color: #666666">.</span>predict(X_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plot the results</span>
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
plt<span style="color: #666666">.</span>scatter(X, distance_list, s<span style="color: #666666">=2.5</span>, c<span style="color: #666666">=</span><span style="color: #BA2121">"black"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_1, color<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>,
|
||||
label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=2"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_2, color<span style="color: #666666">=</span><span style="color: #BA2121">"green"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=5"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_3, color<span style="color: #666666">=</span><span style="color: #BA2121">"m"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=7"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Data"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Darget"</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Decision Tree Regression"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -317,7 +241,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs015.html">16</a></li>
|
||||
<li><a href="._week44-bs016.html">17</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs008.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,30 +210,20 @@ MathJax.Hub.Config({
|
||||
<a name="part0008"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec7" class="anchor">Building a tree, regression </h2>
|
||||
<h2 id="___sec7" class="anchor">General Features </h2>
|
||||
|
||||
<p>
|
||||
There are mainly two steps
|
||||
The overarching approach to decision trees is a top-down approach.
|
||||
|
||||
<ol>
|
||||
<li> We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \) distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \).</li>
|
||||
<li> For every observation that falls into the region \( R_j \) , we make the same prediction, which is simply the mean of the response values for the training observations in \( R_j \).</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li> A leaf provides the classification of a given instance.</li>
|
||||
<li> A node specifies a test of some attribute of the instance.</li>
|
||||
<li> A branch corresponds to a possible values of an attribute.</li>
|
||||
<li> An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.</li>
|
||||
</ul>
|
||||
|
||||
How do we construct the regions \( R_1,\dots,R_J \)? In theory, the
|
||||
regions could have any shape. However, we choose to divide the
|
||||
predictor space into high-dimensional rectangles, or boxes, for
|
||||
simplicity and for ease of interpretation of the resulting predictive
|
||||
model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the
|
||||
MSE, given by
|
||||
|
||||
$$
|
||||
\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2,
|
||||
$$
|
||||
|
||||
<p>
|
||||
where \( \overline{y}_{R_j} \) is the mean response for the training observations
|
||||
within box \( j \).
|
||||
This process is then repeated for the subtree rooted at the new
|
||||
node.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -250,7 +249,7 @@ within box \( j \).
|
||||
<li><a href="._week44-bs016.html">17</a></li>
|
||||
<li><a href="._week44-bs017.html">18</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs009.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,21 +210,20 @@ MathJax.Hub.Config({
|
||||
<a name="part0009"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec8" class="anchor">A top-down approach, recursive binary splitting </h2>
|
||||
<h2 id="___sec8" class="anchor">How do we set it up? </h2>
|
||||
|
||||
<p>
|
||||
Unfortunately, it is computationally infeasible to consider every
|
||||
possible partition of the feature space into \( J \) boxes. The common
|
||||
strategy is to take a top-down approach
|
||||
In simplified terms, the process of training a decision tree and
|
||||
predicting the target features of query instances is as follows:
|
||||
|
||||
<p>
|
||||
The approach is top-down because it begins at the top of the tree (all
|
||||
observations belong to a single region) and then successively splits
|
||||
the predictor space; each split is indicated via two new branches
|
||||
further down on the tree. It is greedy because at each step of the
|
||||
tree-building process, the best split is made at that particular step,
|
||||
rather than looking ahead and picking a split that will lead to a
|
||||
better tree in some future step.
|
||||
<ol>
|
||||
<li> Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature</li>
|
||||
<li> Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process</li>
|
||||
<li> Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the <em>predictions</em> we want to make for new query instances</li>
|
||||
<li> Show query instances to the tree and run down the tree until we arrive at leaf nodes</li>
|
||||
</ol>
|
||||
|
||||
Then we are essentially done!
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -242,7 +250,7 @@ better tree in some future step.
|
||||
<li><a href="._week44-bs017.html">18</a></li>
|
||||
<li><a href="._week44-bs018.html">19</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs010.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,54 +210,99 @@ MathJax.Hub.Config({
|
||||
<a name="part0010"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec9" class="anchor">Making a tree </h2>
|
||||
|
||||
<h2 id="___sec9" class="anchor">Decision trees and Regression </h2>
|
||||
<p>
|
||||
In order to implement the recursive binary splitting we start by selecting
|
||||
the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \)
|
||||
$$
|
||||
\left\{X\vert x_j < s\right\},
|
||||
$$
|
||||
|
||||
and
|
||||
$$
|
||||
\left\{X\vert x_j \geq s\right\},
|
||||
$$
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
so that we obtain the lowest MSE, that is
|
||||
$$
|
||||
\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2,
|
||||
$$
|
||||
steps<span style="color: #666666">=250</span>
|
||||
|
||||
<p>
|
||||
which we want to minimize by considering all predictors
|
||||
\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for
|
||||
each predictor. These values could be determined by randomly assigned
|
||||
numbers or by starting at the midpoint and then proceed till we find
|
||||
an optimal value.
|
||||
distance<span style="color: #666666">=0</span>
|
||||
x<span style="color: #666666">=0</span>
|
||||
distance_list<span style="color: #666666">=</span>[]
|
||||
steps_list<span style="color: #666666">=</span>[]
|
||||
<span style="color: #008000; font-weight: bold">while</span> x<span style="color: #666666"><</span>steps:
|
||||
distance<span style="color: #666666">+=</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randint(<span style="color: #666666">-1</span>,<span style="color: #666666">2</span>)
|
||||
distance_list<span style="color: #666666">.</span>append(distance)
|
||||
x<span style="color: #666666">+=1</span>
|
||||
steps_list<span style="color: #666666">.</span>append(x)
|
||||
plt<span style="color: #666666">.</span>plot(steps_list,distance_list, color<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Random Walk Data"</span>)
|
||||
|
||||
<p>
|
||||
For any \( j \) and \( s \), we define the pair of half-planes where
|
||||
\( \overline{y}_{R_1} \) is the mean response for the training
|
||||
observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean
|
||||
response for the training observations in \( R_2(j,s) \).
|
||||
steps_list<span style="color: #666666">=</span>np<span style="color: #666666">.</span>asarray(steps_list)
|
||||
distance_list<span style="color: #666666">=</span>np<span style="color: #666666">.</span>asarray(distance_list)
|
||||
|
||||
<p>
|
||||
Finding the values of \( j \) and \( s \) that minimize the above equation can be
|
||||
done quite quickly, especially when the number of features \( p \) is not
|
||||
too large.
|
||||
X<span style="color: #666666">=</span>steps_list[:,np<span style="color: #666666">.</span>newaxis]
|
||||
|
||||
<p>
|
||||
Next, we repeat the process, looking
|
||||
for the best predictor and best cutpoint in order to split the data
|
||||
further so as to minimize the MSE within each of the resulting
|
||||
regions. However, this time, instead of splitting the entire predictor
|
||||
space, we split one of the two previously identified regions. We now
|
||||
have three regions. Again, we look to split one of these three regions
|
||||
further, so as to minimize the MSE. The process continues until a
|
||||
stopping criterion is reached; for instance, we may continue until no
|
||||
region contains more than five observations.
|
||||
<span style="color: #408080; font-style: italic">#Polynomial fits</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Degree 2</span>
|
||||
poly_features<span style="color: #666666">=</span>PolynomialFeatures(degree<span style="color: #666666">=2</span>, include_bias<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
X_poly<span style="color: #666666">=</span>poly_features<span style="color: #666666">.</span>fit_transform(X)
|
||||
|
||||
lin_reg<span style="color: #666666">=</span>LinearRegression()
|
||||
poly_fit<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>fit(X_poly,distance_list)
|
||||
b<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>coef_
|
||||
c<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>intercept_
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"2nd degree coefficients:"</span>)
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"zero power: "</span>,c)
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"first power: "</span>, b[<span style="color: #666666">0</span>])
|
||||
<span style="color: #008000">print</span> (<span style="color: #BA2121">"second power: "</span>,b[<span style="color: #666666">1</span>])
|
||||
|
||||
z <span style="color: #666666">=</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">0</span>, steps, <span style="color: #666666">.01</span>)
|
||||
z_mod<span style="color: #666666">=</span>b[<span style="color: #666666">1</span>]<span style="color: #666666">*</span>z<span style="color: #666666">**2+</span>b[<span style="color: #666666">0</span>]<span style="color: #666666">*</span>z<span style="color: #666666">+</span>c
|
||||
|
||||
fit_mod<span style="color: #666666">=</span>b[<span style="color: #666666">1</span>]<span style="color: #666666">*</span>X<span style="color: #666666">**2+</span>b[<span style="color: #666666">0</span>]<span style="color: #666666">*</span>X<span style="color: #666666">+</span>c
|
||||
plt<span style="color: #666666">.</span>plot(z, z_mod, color<span style="color: #666666">=</span><span style="color: #BA2121">'r'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"2nd Degree Fit"</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Polynomial Regression"</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Steps"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Distance"</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Degree 10</span>
|
||||
poly_features10<span style="color: #666666">=</span>PolynomialFeatures(degree<span style="color: #666666">=10</span>, include_bias<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
X_poly10<span style="color: #666666">=</span>poly_features10<span style="color: #666666">.</span>fit_transform(X)
|
||||
|
||||
poly_fit10<span style="color: #666666">=</span>lin_reg<span style="color: #666666">.</span>fit(X_poly10,distance_list)
|
||||
|
||||
y_plot<span style="color: #666666">=</span>poly_fit10<span style="color: #666666">.</span>predict(X_poly10)
|
||||
plt<span style="color: #666666">.</span>plot(X, y_plot, color<span style="color: #666666">=</span><span style="color: #BA2121">'black'</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"10th Degree Fit"</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#Decision Tree Regression</span>
|
||||
<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> DecisionTreeRegressor
|
||||
regr_1<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=2</span>)
|
||||
regr_2<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=5</span>)
|
||||
regr_3<span style="color: #666666">=</span>DecisionTreeRegressor(max_depth<span style="color: #666666">=7</span>)
|
||||
regr_1<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
regr_2<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
regr_3<span style="color: #666666">.</span>fit(X, distance_list)
|
||||
|
||||
X_test <span style="color: #666666">=</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">0.0</span>, steps, <span style="color: #666666">0.01</span>)[:, np<span style="color: #666666">.</span>newaxis]
|
||||
y_1 <span style="color: #666666">=</span> regr_1<span style="color: #666666">.</span>predict(X_test)
|
||||
y_2 <span style="color: #666666">=</span> regr_2<span style="color: #666666">.</span>predict(X_test)
|
||||
y_3<span style="color: #666666">=</span>regr_3<span style="color: #666666">.</span>predict(X_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Plot the results</span>
|
||||
plt<span style="color: #666666">.</span>figure()
|
||||
plt<span style="color: #666666">.</span>scatter(X, distance_list, s<span style="color: #666666">=2.5</span>, c<span style="color: #666666">=</span><span style="color: #BA2121">"black"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"data"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_1, color<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>,
|
||||
label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=2"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_2, color<span style="color: #666666">=</span><span style="color: #BA2121">"green"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=5"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X_test, y_3, color<span style="color: #666666">=</span><span style="color: #BA2121">"m"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"max_depth=7"</span>, linewidth<span style="color: #666666">=2</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Data"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Darget"</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Decision Tree Regression"</span>)
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -275,7 +329,7 @@ region contains more than five observations.
|
||||
<li><a href="._week44-bs018.html">19</a></li>
|
||||
<li><a href="._week44-bs019.html">20</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs011.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -199,23 +208,32 @@ MathJax.Hub.Config({
|
||||
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
||||
|
||||
<a name="part0011"></a>
|
||||
<!-- !split -->
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec10" class="anchor">Pruning the tree </h2>
|
||||
<h2 id="___sec10" class="anchor">Building a tree, regression </h2>
|
||||
|
||||
<p>
|
||||
The above procedure is rather straightforward, but leads often to
|
||||
overfitting and unnecessarily large and complicated trees. The basic
|
||||
idea is to grow a large tree \( T_0 \) and then prune it back in order to
|
||||
obtain a subtree. A smaller tree with fewer splits (fewer regions) can
|
||||
lead to smaller variance and better interpretation at the cost of a
|
||||
little more bias.
|
||||
There are mainly two steps
|
||||
|
||||
<ol>
|
||||
<li> We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \) distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \).</li>
|
||||
<li> For every observation that falls into the region \( R_j \) , we make the same prediction, which is simply the mean of the response values for the training observations in \( R_j \).</li>
|
||||
</ol>
|
||||
|
||||
How do we construct the regions \( R_1,\dots,R_J \)? In theory, the
|
||||
regions could have any shape. However, we choose to divide the
|
||||
predictor space into high-dimensional rectangles, or boxes, for
|
||||
simplicity and for ease of interpretation of the resulting predictive
|
||||
model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the
|
||||
MSE, given by
|
||||
|
||||
$$
|
||||
\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2,
|
||||
$$
|
||||
|
||||
<p>
|
||||
The so-called Cost complexity pruning algorithm gives us a
|
||||
way to do just this. Rather than considering every possible subtree,
|
||||
we consider a sequence of trees indexed by a nonnegative tuning
|
||||
parameter \( \alpha \).
|
||||
where \( \overline{y}_{R_j} \) is the mean response for the training observations
|
||||
within box \( j \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -243,7 +261,7 @@ parameter \( \alpha \).
|
||||
<li><a href="._week44-bs019.html">20</a></li>
|
||||
<li><a href="._week44-bs020.html">21</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs012.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,33 +210,21 @@ MathJax.Hub.Config({
|
||||
<a name="part0012"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec11" class="anchor">Cost complexity pruning </h2>
|
||||
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
|
||||
$$
|
||||
\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
|
||||
$$
|
||||
|
||||
is as small as possible. Here \( \overline{T} \) is
|
||||
the number of terminal nodes of the tree \( T \) , \( R_m \) is the
|
||||
rectangle (i.e. the subset of predictor space) corresponding to the \( m \)-th terminal node.
|
||||
<h2 id="___sec11" class="anchor">A top-down approach, recursive binary splitting </h2>
|
||||
|
||||
<p>
|
||||
The tuning parameter \( \alpha \) controls a trade-off between the subtree’s
|
||||
com- plexity and its fit to the training data. When \( \alpha = 0 \), then the
|
||||
subtree \( T \) will simply equal \( T_0 \),
|
||||
because then the above equation just measures the
|
||||
training error.
|
||||
However, as \( \alpha \) increases, there is a price to pay for
|
||||
having a tree with many terminal nodes. The above equation will
|
||||
tend to be minimized for a smaller subtree.
|
||||
Unfortunately, it is computationally infeasible to consider every
|
||||
possible partition of the feature space into \( J \) boxes. The common
|
||||
strategy is to take a top-down approach
|
||||
|
||||
<p>
|
||||
It turns out that as we increase \( \alpha \) from zero
|
||||
branches get pruned from the tree in a nested and predictable fashion,
|
||||
so obtaining the whole sequence of subtrees as a function of \( \alpha \) is
|
||||
easy. We can select a value of \( \alpha \) using a validation set or using
|
||||
cross-validation. We then return to the full data set and obtain the
|
||||
subtree corresponding to \( \alpha \).
|
||||
The approach is top-down because it begins at the top of the tree (all
|
||||
observations belong to a single region) and then successively splits
|
||||
the predictor space; each split is indicated via two new branches
|
||||
further down on the tree. It is greedy because at each step of the
|
||||
tree-building process, the best split is made at that particular step,
|
||||
rather than looking ahead and picking a split that will lead to a
|
||||
better tree in some future step.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -255,7 +252,7 @@ subtree corresponding to \( \alpha \).
|
||||
<li><a href="._week44-bs020.html">21</a></li>
|
||||
<li><a href="._week44-bs021.html">22</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs013.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,29 +210,53 @@ MathJax.Hub.Config({
|
||||
<a name="part0013"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec12" class="anchor">Schematic Regression Procedure </h2>
|
||||
<h2 id="___sec12" class="anchor">Making a tree </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
In order to implement the recursive binary splitting we start by selecting
|
||||
the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \)
|
||||
$$
|
||||
\left\{X\vert x_j < s\right\},
|
||||
$$
|
||||
|
||||
<ol>
|
||||
<li> Use recursive binary splitting to grow a large tree on the training data, stopping only when each terminal node has fewer than some minimum number of observations.</li>
|
||||
<li> Apply cost complexity pruning to the large tree in order to obtain a sequence of best subtrees, as a function of \( \alpha \).</li>
|
||||
<li> Use for example \( K \)-fold cross-validation to choose \( \alpha \). Divide the training observations into \( K \) folds. For each \( k=1,2,\dots,K \) we:</li>
|
||||
and
|
||||
$$
|
||||
\left\{X\vert x_j \geq s\right\},
|
||||
$$
|
||||
|
||||
<ul>
|
||||
<li> repeat steps 1 and 2 on all but the \( k \)-th fold of the training data.</li>
|
||||
<li> Then we valuate the mean squared prediction error on the data in the left-out \( k \)-th fold, as a function of \( \alpha \).</li>
|
||||
<li> Finally we average the results for each value of \( \alpha \), and pick \( \alpha \) to minimize the average error.</li>
|
||||
</ul>
|
||||
so that we obtain the lowest MSE, that is
|
||||
$$
|
||||
\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2,
|
||||
$$
|
||||
|
||||
<li> Return the subtree from Step 2 that corresponds to the chosen value of \( \alpha \).</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
which we want to minimize by considering all predictors
|
||||
\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for
|
||||
each predictor. These values could be determined by randomly assigned
|
||||
numbers or by starting at the midpoint and then proceed till we find
|
||||
an optimal value.
|
||||
|
||||
<p>
|
||||
For any \( j \) and \( s \), we define the pair of half-planes where
|
||||
\( \overline{y}_{R_1} \) is the mean response for the training
|
||||
observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean
|
||||
response for the training observations in \( R_2(j,s) \).
|
||||
|
||||
<p>
|
||||
Finding the values of \( j \) and \( s \) that minimize the above equation can be
|
||||
done quite quickly, especially when the number of features \( p \) is not
|
||||
too large.
|
||||
|
||||
<p>
|
||||
Next, we repeat the process, looking
|
||||
for the best predictor and best cutpoint in order to split the data
|
||||
further so as to minimize the MSE within each of the resulting
|
||||
regions. However, this time, instead of splitting the entire predictor
|
||||
space, we split one of the two previously identified regions. We now
|
||||
have three regions. Again, we look to split one of these three regions
|
||||
further, so as to minimize the MSE. The process continues until a
|
||||
stopping criterion is reached; for instance, we may continue until no
|
||||
region contains more than five observations.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -251,7 +284,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs021.html">22</a></li>
|
||||
<li><a href="._week44-bs022.html">23</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs014.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -199,23 +208,23 @@ MathJax.Hub.Config({
|
||||
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
||||
|
||||
<a name="part0014"></a>
|
||||
<!-- !split -->
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec13" class="anchor">A Classification Tree </h2>
|
||||
<h2 id="___sec13" class="anchor">Pruning the tree </h2>
|
||||
|
||||
<p>
|
||||
A classification tree is very similar to a regression tree, except
|
||||
that it is used to predict a qualitative response rather than a
|
||||
quantitative one. Recall that for a regression tree, the predicted
|
||||
response for an observation is given by the mean response of the
|
||||
training observations that belong to the same terminal node. In
|
||||
contrast, for a classification tree, we predict that each observation
|
||||
belongs to the most commonly occurring class of training observations
|
||||
in the region to which it belongs. In interpreting the results of a
|
||||
classification tree, we are often interested not only in the class
|
||||
prediction corresponding to a particular terminal node region, but
|
||||
also in the class proportions among the training observations that
|
||||
fall into that region.
|
||||
The above procedure is rather straightforward, but leads often to
|
||||
overfitting and unnecessarily large and complicated trees. The basic
|
||||
idea is to grow a large tree \( T_0 \) and then prune it back in order to
|
||||
obtain a subtree. A smaller tree with fewer splits (fewer regions) can
|
||||
lead to smaller variance and better interpretation at the cost of a
|
||||
little more bias.
|
||||
|
||||
<p>
|
||||
The so-called Cost complexity pruning algorithm gives us a
|
||||
way to do just this. Rather than considering every possible subtree,
|
||||
we consider a sequence of trees indexed by a nonnegative tuning
|
||||
parameter \( \alpha \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -243,7 +252,7 @@ fall into that region.
|
||||
<li><a href="._week44-bs022.html">23</a></li>
|
||||
<li><a href="._week44-bs023.html">24</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs015.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,26 +210,33 @@ MathJax.Hub.Config({
|
||||
<a name="part0015"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec14" class="anchor">Growing a classification tree </h2>
|
||||
<h2 id="___sec14" class="anchor">Cost complexity pruning </h2>
|
||||
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
|
||||
$$
|
||||
\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
|
||||
$$
|
||||
|
||||
is as small as possible. Here \( \overline{T} \) is
|
||||
the number of terminal nodes of the tree \( T \) , \( R_m \) is the
|
||||
rectangle (i.e. the subset of predictor space) corresponding to the \( m \)-th terminal node.
|
||||
|
||||
<p>
|
||||
The task of growing a
|
||||
classification tree is quite similar to the task of growing a
|
||||
regression tree. Just as in the regression setting, we use recursive
|
||||
binary splitting to grow a classification tree. However, in the
|
||||
classification setting, the MSE cannot be used as a criterion for making
|
||||
the binary splits. A natural alternative to MSE is the <b>classification
|
||||
error rate</b>. Since we plan to assign an observation in a given region
|
||||
to the most commonly occurring error rate class of training
|
||||
observations in that region, the classification error rate is simply
|
||||
the fraction of the training observations in that region that do not
|
||||
belong to the most common class.
|
||||
The tuning parameter \( \alpha \) controls a trade-off between the subtree’s
|
||||
com- plexity and its fit to the training data. When \( \alpha = 0 \), then the
|
||||
subtree \( T \) will simply equal \( T_0 \),
|
||||
because then the above equation just measures the
|
||||
training error.
|
||||
However, as \( \alpha \) increases, there is a price to pay for
|
||||
having a tree with many terminal nodes. The above equation will
|
||||
tend to be minimized for a smaller subtree.
|
||||
|
||||
<p>
|
||||
When building a classification tree, either the Gini index or the
|
||||
entropy are typically used to evaluate the quality of a particular
|
||||
split, since these two approaches are more sensitive to node purity
|
||||
than is the classification error rate.
|
||||
It turns out that as we increase \( \alpha \) from zero
|
||||
branches get pruned from the tree in a nested and predictable fashion,
|
||||
so obtaining the whole sequence of subtrees as a function of \( \alpha \) is
|
||||
easy. We can select a value of \( \alpha \) using a validation set or using
|
||||
cross-validation. We then return to the full data set and obtain the
|
||||
subtree corresponding to \( \alpha \).
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -248,7 +264,7 @@ than is the classification error rate.
|
||||
<li><a href="._week44-bs023.html">24</a></li>
|
||||
<li><a href="._week44-bs024.html">25</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs016.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,53 +210,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0016"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec15" class="anchor">Classification tree, how to split nodes </h2>
|
||||
<h2 id="___sec15" class="anchor">Schematic Regression Procedure </h2>
|
||||
|
||||
<p>
|
||||
If our targets are the outcome of a classification process that takes
|
||||
for example \( k=1,2,\dots,K \) values, the only thing we need to think of
|
||||
is to set up the splitting criteria for each node.
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<p>
|
||||
We define a PDF \( p_{mk} \) that represents the number of observations of
|
||||
a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent
|
||||
this likelihood function in terms of the proportion \( I(y_i=k) \) of
|
||||
observations of this class in the region \( R_m \) as
|
||||
|
||||
$$
|
||||
p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i=k).
|
||||
$$
|
||||
|
||||
<p>
|
||||
We let \( p_{mk} \) represent the majority class of observations in region
|
||||
\( m \). The three most common ways of splitting a node are given by
|
||||
<ol>
|
||||
<li> Use recursive binary splitting to grow a large tree on the training data, stopping only when each terminal node has fewer than some minimum number of observations.</li>
|
||||
<li> Apply cost complexity pruning to the large tree in order to obtain a sequence of best subtrees, as a function of \( \alpha \).</li>
|
||||
<li> Use for example \( K \)-fold cross-validation to choose \( \alpha \). Divide the training observations into \( K \) folds. For each \( k=1,2,\dots,K \) we:</li>
|
||||
|
||||
<ul>
|
||||
<li> Misclassification error</li>
|
||||
<li> repeat steps 1 and 2 on all but the \( k \)-th fold of the training data.</li>
|
||||
<li> Then we valuate the mean squared prediction error on the data in the left-out \( k \)-th fold, as a function of \( \alpha \).</li>
|
||||
<li> Finally we average the results for each value of \( \alpha \), and pick \( \alpha \) to minimize the average error.</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i\ne k) = 1-p_{mk}.
|
||||
$$
|
||||
<li> Return the subtree from Step 2 that corresponds to the chosen value of \( \alpha \).</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<ul>
|
||||
<li> Gini index \( g \)</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
g = \sum_{k=1}^K p_{mk}(1-p_{mk}).
|
||||
$$
|
||||
|
||||
|
||||
<ul>
|
||||
<li> Information entropy or just entropy \( s \)</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -274,7 +260,7 @@ $$
|
||||
<li><a href="._week44-bs024.html">25</a></li>
|
||||
<li><a href="._week44-bs025.html">26</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs017.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,44 +210,22 @@ MathJax.Hub.Config({
|
||||
<a name="part0017"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec16" class="anchor">Visualizing the Tree, Classification </h2>
|
||||
<h2 id="___sec16" class="anchor">A Classification Tree </h2>
|
||||
|
||||
<p>
|
||||
A classification tree is very similar to a regression tree, except
|
||||
that it is used to predict a qualitative response rather than a
|
||||
quantitative one. Recall that for a regression tree, the predicted
|
||||
response for an observation is given by the mean response of the
|
||||
training observations that belong to the same terminal node. In
|
||||
contrast, for a classification tree, we predict that each observation
|
||||
belongs to the most commonly occurring class of training observations
|
||||
in the region to which it belongs. In interpreting the results of a
|
||||
classification tree, we are often interested not only in the class
|
||||
prediction corresponding to a particular terminal node region, but
|
||||
also in the class proportions among the training observations that
|
||||
fall into that region.
|
||||
|
||||
<!-- 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">os</span>
|
||||
<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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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.metrics</span> <span style="color: #008000; font-weight: bold">import</span> confusion_matrix
|
||||
<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> export_graphviz
|
||||
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</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>
|
||||
|
||||
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
X <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(cancer<span style="color: #666666">.</span>data, columns<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>feature_names)
|
||||
<span style="color: #008000">print</span>(X)
|
||||
y <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>Categorical<span style="color: #666666">.</span>from_codes(cancer<span style="color: #666666">.</span>target, cancer<span style="color: #666666">.</span>target_names)
|
||||
y <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>get_dummies(y)
|
||||
<span style="color: #008000">print</span>(y)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, random_state<span style="color: #666666">=1</span>)
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=5</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/cancer.dot"</span>,
|
||||
feature_names<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>feature_names,
|
||||
class_names<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>target_names,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -265,7 +252,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<li><a href="._week44-bs025.html">26</a></li>
|
||||
<li><a href="._week44-bs026.html">27</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs018.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,35 +210,27 @@ MathJax.Hub.Config({
|
||||
<a name="part0018"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec17" class="anchor">Visualizing the Tree, The Moons </h2>
|
||||
<h2 id="___sec17" class="anchor">Growing a classification tree </h2>
|
||||
|
||||
<p>
|
||||
The task of growing a
|
||||
classification tree is quite similar to the task of growing a
|
||||
regression tree. Just as in the regression setting, we use recursive
|
||||
binary splitting to grow a classification tree. However, in the
|
||||
classification setting, the MSE cannot be used as a criterion for making
|
||||
the binary splits. A natural alternative to MSE is the <b>classification
|
||||
error rate</b>. Since we plan to assign an observation in a given region
|
||||
to the most commonly occurring error rate class of training
|
||||
observations in that region, the classification error rate is simply
|
||||
the fraction of the training observations in that region that do not
|
||||
belong to the most common class.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Common imports</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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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> make_moons
|
||||
<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> export_graphviz
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
<p>
|
||||
When building a classification tree, either the Gini index or the
|
||||
entropy are typically used to evaluate the quality of a particular
|
||||
split, since these two approaches are more sensitive to node purity
|
||||
than is the classification error rate.
|
||||
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
X, y <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=100</span>, noise<span style="color: #666666">=0.25</span>, random_state<span style="color: #666666">=53</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X,y,random_state<span style="color: #666666">=0</span>)
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=5</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/moons.dot"</span>,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/moons.dot -o DataFiles/moons.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -256,7 +257,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<li><a href="._week44-bs026.html">27</a></li>
|
||||
<li><a href="._week44-bs027.html">28</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs019.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,20 +210,52 @@ MathJax.Hub.Config({
|
||||
<a name="part0019"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec18" class="anchor">Algorithms for Setting up Decision Trees </h2>
|
||||
<h2 id="___sec18" class="anchor">Classification tree, how to split nodes </h2>
|
||||
|
||||
<p>
|
||||
Two algorithms stand out in the set up of decision trees:
|
||||
If our targets are the outcome of a classification process that takes
|
||||
for example \( k=1,2,\dots,K \) values, the only thing we need to think of
|
||||
is to set up the splitting criteria for each node.
|
||||
|
||||
<ol>
|
||||
<li> The CART (Classification And Regression Tree) algorithm for both classification and regression</li>
|
||||
<li> The ID3 algorithm based on the computation of the information gain for classification</li>
|
||||
</ol>
|
||||
<p>
|
||||
We define a PDF \( p_{mk} \) that represents the number of observations of
|
||||
a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent
|
||||
this likelihood function in terms of the proportion \( I(y_i=k) \) of
|
||||
observations of this class in the region \( R_m \) as
|
||||
|
||||
We discuss both algorithms with applications here. The popular library
|
||||
<b>Scikit-Learn</b> uses the CART algorithm. For classification problems
|
||||
you can use either the <b>gini</b> index or the <b>entropy</b> to split a tree
|
||||
in two branches.
|
||||
$$
|
||||
p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i=k).
|
||||
$$
|
||||
|
||||
<p>
|
||||
We let \( p_{mk} \) represent the majority class of observations in region
|
||||
\( m \). The three most common ways of splitting a node are given by
|
||||
|
||||
<ul>
|
||||
<li> Misclassification error</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i\ne k) = 1-p_{mk}.
|
||||
$$
|
||||
|
||||
|
||||
<ul>
|
||||
<li> Gini index \( g \)</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
g = \sum_{k=1}^K p_{mk}(1-p_{mk}).
|
||||
$$
|
||||
|
||||
|
||||
<ul>
|
||||
<li> Information entropy or just entropy \( s \)</li>
|
||||
</ul>
|
||||
|
||||
$$
|
||||
s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -242,7 +283,7 @@ in two branches.
|
||||
<li><a href="._week44-bs027.html">28</a></li>
|
||||
<li><a href="._week44-bs028.html">29</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs020.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,30 +210,44 @@ MathJax.Hub.Config({
|
||||
<a name="part0020"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec19" class="anchor">The CART algorithm for Classification </h2>
|
||||
|
||||
<h2 id="___sec19" class="anchor">Visualizing the Tree, Classification </h2>
|
||||
<p>
|
||||
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
|
||||
This could be for example a threshold set by a number below a certain circumference of a malign tumor.
|
||||
|
||||
<p>
|
||||
How do we find these two quantities?
|
||||
We search for the pair \( (k,t_k) \) that produces the purest subset using for example the <b>gini</b> factor \( G \).
|
||||
The cost function it tries to minimize is then
|
||||
$$
|
||||
C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
|
||||
$$
|
||||
<!-- 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">os</span>
|
||||
<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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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.metrics</span> <span style="color: #008000; font-weight: bold">import</span> confusion_matrix
|
||||
<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> export_graphviz
|
||||
|
||||
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
|
||||
is the number of instances in the left/right subset
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</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>
|
||||
|
||||
<p>
|
||||
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
|
||||
and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
|
||||
\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
|
||||
hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
|
||||
\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
|
||||
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
X <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(cancer<span style="color: #666666">.</span>data, columns<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>feature_names)
|
||||
<span style="color: #008000">print</span>(X)
|
||||
y <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>Categorical<span style="color: #666666">.</span>from_codes(cancer<span style="color: #666666">.</span>target, cancer<span style="color: #666666">.</span>target_names)
|
||||
y <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>get_dummies(y)
|
||||
<span style="color: #008000">print</span>(y)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, random_state<span style="color: #666666">=1</span>)
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=5</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/cancer.dot"</span>,
|
||||
feature_names<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>feature_names,
|
||||
class_names<span style="color: #666666">=</span>cancer<span style="color: #666666">.</span>target_names,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -251,7 +274,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl
|
||||
<li><a href="._week44-bs028.html">29</a></li>
|
||||
<li><a href="._week44-bs029.html">30</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs021.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,31 +210,35 @@ MathJax.Hub.Config({
|
||||
<a name="part0021"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec20" class="anchor">The CART algorithm for Regression </h2>
|
||||
|
||||
<h2 id="___sec20" class="anchor">Visualizing the Tree, The Moons </h2>
|
||||
<p>
|
||||
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
|
||||
training set in a way that minimizes say the <b>gini</b> or <b>entropy</b> impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
|
||||
$$
|
||||
C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
|
||||
$$
|
||||
|
||||
Here the MSE for a specific node is defined as
|
||||
$$
|
||||
\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_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: #408080; font-style: italic"># Common imports</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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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> make_moons
|
||||
<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> export_graphviz
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
|
||||
with
|
||||
$$
|
||||
\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i,
|
||||
$$
|
||||
|
||||
the mean value of all observations in a specific node.
|
||||
|
||||
<p>
|
||||
Without any regularization, the regression task for decision trees,
|
||||
just like for classification tasks, is prone to overfitting.
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
X, y <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=100</span>, noise<span style="color: #666666">=0.25</span>, random_state<span style="color: #666666">=53</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X,y,random_state<span style="color: #666666">=0</span>)
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=5</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/moons.dot"</span>,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/moons.dot -o DataFiles/moons.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -252,7 +265,7 @@ just like for classification tasks, is prone to overfitting.
|
||||
<li><a href="._week44-bs029.html">30</a></li>
|
||||
<li><a href="._week44-bs030.html">31</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs022.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,48 +210,21 @@ MathJax.Hub.Config({
|
||||
<a name="part0022"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec21" class="anchor">Computing the Gini index </h2>
|
||||
<h2 id="___sec21" class="anchor">Algorithms for Setting up Decision Trees </h2>
|
||||
|
||||
<p>
|
||||
The example we will look at is a classical one in many Machine
|
||||
Learning applications. Based on various meteorological features, we
|
||||
have several so-called attributes which decide whether we at the end
|
||||
will do some outdoor activity like skiing, going for a bike ride etc
|
||||
etc. The table here contains the feautures <b>outlook</b>, <b>temperature</b>,
|
||||
<b>humidity</b> and <b>wind</b>. The target or output is whether we ride
|
||||
(True=1) or whether we do something else that day (False=0). The
|
||||
attributes for each feature are then sunny, overcast and rain for the
|
||||
outlook, hot, cold and mild for temperature, high and normal for
|
||||
humidity and weak and strong for wind.
|
||||
Two algorithms stand out in the set up of decision trees:
|
||||
|
||||
<p>
|
||||
The table here summarizes the various attributes and
|
||||
<ol>
|
||||
<li> The CART (Classification And Regression Tree) algorithm for both classification and regression</li>
|
||||
<li> The ID3 algorithm based on the computation of the information gain for classification</li>
|
||||
</ol>
|
||||
|
||||
We discuss both algorithms with applications here. The popular library
|
||||
<b>Scikit-Learn</b> uses the CART algorithm. For classification problems
|
||||
you can use either the <b>gini</b> index or the <b>entropy</b> to split a tree
|
||||
in two branches.
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-4">
|
||||
<table class="table table-striped table-hover table-condensed">
|
||||
<thead>
|
||||
<tr><td align="center"><b>Day</b></td> <td align="center"><b>Outlook </b></td> <td align="center"><b>Temperature</b></td> <td align="center"><b>Humidity</b></td> <td align="center"><b> Wind </b></td> <td align="center"><b>Ride</b></td> </tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td align="center"> 1 </td> <td align="center"> Sunny </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 2 </td> <td align="center"> Sunny </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 3 </td> <td align="center"> Overcast </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 4 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 5 </td> <td align="center"> Rain </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 6 </td> <td align="center"> Rain </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 7 </td> <td align="center"> Overcast </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 8 </td> <td align="center"> Sunny </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 9 </td> <td align="center"> Sunny </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 10 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 11 </td> <td align="center"> Sunny </td> <td align="center"> Mild </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 12 </td> <td align="center"> Overcast </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 13 </td> <td align="center"> Overcast </td> <td align="center"> Hot </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 14 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 0 </td> </tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- col-xs-4 -->
|
||||
</div> <!-- cell row -->
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -269,7 +251,7 @@ The table here summarizes the various attributes and
|
||||
<li><a href="._week44-bs030.html">31</a></li>
|
||||
<li><a href="._week44-bs031.html">32</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs023.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,79 +210,30 @@ MathJax.Hub.Config({
|
||||
<a name="part0023"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec22" class="anchor">Simple Python Code to read in Data and perform Classification </h2>
|
||||
<h2 id="___sec22" class="anchor">The CART algorithm for Classification </h2>
|
||||
|
||||
<p>
|
||||
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
|
||||
This could be for example a threshold set by a number below a certain circumference of a malign tumor.
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Common imports</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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.tree</span> <span style="color: #008000; font-weight: bold">import</span> export_graphviz
|
||||
<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, OneHotEncoder
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.compose</span> <span style="color: #008000; font-weight: bold">import</span> ColumnTransformer
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
<p>
|
||||
How do we find these two quantities?
|
||||
We search for the pair \( (k,t_k) \) that produces the purest subset using for example the <b>gini</b> factor \( G \).
|
||||
The cost function it tries to minimize is then
|
||||
$$
|
||||
C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
|
||||
$$
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR <span style="color: #666666">=</span> <span style="color: #BA2121">"Results"</span>
|
||||
FIGURE_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"Results/FigureFiles"</span>
|
||||
DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"DataFiles/"</span>
|
||||
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
|
||||
is the number of instances in the left/right subset
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(PROJECT_ROOT_DIR):
|
||||
os<span style="color: #666666">.</span>mkdir(PROJECT_ROOT_DIR)
|
||||
<p>
|
||||
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
|
||||
and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
|
||||
\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
|
||||
hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
|
||||
\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(FIGURE_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(DATA_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">image_path</span>(fig_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">data_path</span>(dat_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
|
||||
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">".png"</span>, <span style="color: #008000">format</span><span style="color: #666666">=</span><span style="color: #BA2121">'png'</span>)
|
||||
|
||||
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">"rideclass.csv"</span>),<span style="color: #BA2121">'r'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Read the experimental data with Pandas</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
||||
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile,names <span style="color: #666666">=</span> (<span style="color: #BA2121">'Outlook'</span>,<span style="color: #BA2121">'Temperature'</span>,<span style="color: #BA2121">'Humidity'</span>,<span style="color: #BA2121">'Wind'</span>,<span style="color: #BA2121">'Ride'</span>))
|
||||
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(ridedata)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Features and targets</span>
|
||||
X <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">'Ride'</span>]<span style="color: #666666">.</span>values
|
||||
y <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">'Ride'</span>]<span style="color: #666666">.</span>values
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
|
||||
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">"ignore"</span>)
|
||||
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
|
||||
encoder<span style="color: #666666">.</span>fit(X)
|
||||
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
|
||||
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
|
||||
<span style="color: #008000">print</span>(X)
|
||||
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X, y)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Train set accuracy with Decision Tree: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(tree_clf<span style="color: #666666">.</span>score(X,y)))
|
||||
<span style="color: #408080; font-style: italic">#transfer to a decision tree graph</span>
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/ride.dot"</span>,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -300,7 +260,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<li><a href="._week44-bs031.html">32</a></li>
|
||||
<li><a href="._week44-bs032.html">33</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs024.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,81 +210,31 @@ MathJax.Hub.Config({
|
||||
<a name="part0024"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec23" class="anchor">Computing the Gini Factor </h2>
|
||||
<h2 id="___sec23" class="anchor">The CART algorithm for Regression </h2>
|
||||
|
||||
<p>
|
||||
The above functions (gini, entropy and misclassification error) are
|
||||
important components of the so-called CART algorithm. We will discuss
|
||||
this algorithm below after we have discussed the information gain
|
||||
algorithm ID3.
|
||||
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
|
||||
training set in a way that minimizes say the <b>gini</b> or <b>entropy</b> impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
|
||||
$$
|
||||
C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
|
||||
$$
|
||||
|
||||
Here the MSE for a specific node is defined as
|
||||
$$
|
||||
\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2,
|
||||
$$
|
||||
|
||||
with
|
||||
$$
|
||||
\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i,
|
||||
$$
|
||||
|
||||
the mean value of all observations in a specific node.
|
||||
|
||||
<p>
|
||||
In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
|
||||
Without any regularization, the regression task for decision trees,
|
||||
just like for classification tasks, is prone to overfitting.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Split a dataset based on an attribute and an attribute value</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_split</span>(index, value, dataset):
|
||||
left, right <span style="color: #666666">=</span> <span style="color: #008000">list</span>(), <span style="color: #008000">list</span>()
|
||||
<span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset:
|
||||
<span style="color: #008000; font-weight: bold">if</span> row[index] <span style="color: #666666"><</span> value:
|
||||
left<span style="color: #666666">.</span>append(row)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
right<span style="color: #666666">.</span>append(row)
|
||||
<span style="color: #008000; font-weight: bold">return</span> left, right
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Calculate the Gini index for a split dataset</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">gini_index</span>(groups, classes):
|
||||
<span style="color: #408080; font-style: italic"># count all samples at split point</span>
|
||||
n_instances <span style="color: #666666">=</span> <span style="color: #008000">float</span>(<span style="color: #008000">sum</span>([<span style="color: #008000">len</span>(group) <span style="color: #008000; font-weight: bold">for</span> group <span style="color: #AA22FF; font-weight: bold">in</span> groups]))
|
||||
<span style="color: #408080; font-style: italic"># sum weighted Gini index for each group</span>
|
||||
gini <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> group <span style="color: #AA22FF; font-weight: bold">in</span> groups:
|
||||
size <span style="color: #666666">=</span> <span style="color: #008000">float</span>(<span style="color: #008000">len</span>(group))
|
||||
<span style="color: #408080; font-style: italic"># avoid divide by zero</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> size <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
<span style="color: #008000; font-weight: bold">continue</span>
|
||||
score <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
<span style="color: #408080; font-style: italic"># score the group based on the score for each class</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> class_val <span style="color: #AA22FF; font-weight: bold">in</span> classes:
|
||||
p <span style="color: #666666">=</span> [row[<span style="color: #666666">-1</span>] <span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> group]<span style="color: #666666">.</span>count(class_val) <span style="color: #666666">/</span> size
|
||||
score <span style="color: #666666">+=</span> p <span style="color: #666666">*</span> p
|
||||
<span style="color: #408080; font-style: italic"># weight the group score by its relative size</span>
|
||||
gini <span style="color: #666666">+=</span> (<span style="color: #666666">1.0</span> <span style="color: #666666">-</span> score) <span style="color: #666666">*</span> (size <span style="color: #666666">/</span> n_instances)
|
||||
<span style="color: #008000; font-weight: bold">return</span> gini
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Select the best split point for a dataset</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">get_split</span>(dataset):
|
||||
class_values <span style="color: #666666">=</span> <span style="color: #008000">list</span>(<span style="color: #008000">set</span>(row[<span style="color: #666666">-1</span>] <span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset))
|
||||
b_index, b_value, b_score, b_groups <span style="color: #666666">=</span> <span style="color: #666666">999</span>, <span style="color: #666666">999</span>, <span style="color: #666666">999</span>, <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> index <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(dataset[<span style="color: #666666">0</span>])<span style="color: #666666">-1</span>):
|
||||
<span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset:
|
||||
groups <span style="color: #666666">=</span> test_split(index, row[index], dataset)
|
||||
gini <span style="color: #666666">=</span> gini_index(groups, class_values)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'X</span><span style="color: #BB6688; font-weight: bold">%d</span><span style="color: #BA2121"> < </span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121"> Gini=</span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> ((index<span style="color: #666666">+1</span>), row[index], gini))
|
||||
<span style="color: #008000; font-weight: bold">if</span> gini <span style="color: #666666"><</span> b_score:
|
||||
b_index, b_value, b_score, b_groups <span style="color: #666666">=</span> index, row[index], gini, groups
|
||||
<span style="color: #008000; font-weight: bold">return</span> {<span style="color: #BA2121">'index'</span>:b_index, <span style="color: #BA2121">'value'</span>:b_value, <span style="color: #BA2121">'groups'</span>:b_groups}
|
||||
|
||||
dataset <span style="color: #666666">=</span> [[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>]]
|
||||
|
||||
split <span style="color: #666666">=</span> get_split(dataset)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Split: [X</span><span style="color: #BB6688; font-weight: bold">%d</span><span style="color: #BA2121"> < </span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121">]'</span> <span style="color: #666666">%</span> ((split[<span style="color: #BA2121">'index'</span>]<span style="color: #666666">+1</span>), split[<span style="color: #BA2121">'value'</span>]))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -302,7 +261,7 @@ split <span style="color: #666666">=</span> get_split(dataset)
|
||||
<li><a href="._week44-bs032.html">33</a></li>
|
||||
<li><a href="._week44-bs033.html">34</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs025.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,39 +210,48 @@ MathJax.Hub.Config({
|
||||
<a name="part0025"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec24" class="anchor">Entropy and the ID3 algorithm </h2>
|
||||
<h2 id="___sec24" class="anchor">Computing the Gini index </h2>
|
||||
|
||||
<p>
|
||||
ID3, learns decision trees by constructing
|
||||
them topdown, beginning with the question <b>which attribute should be tested at the root of the tree</b>?
|
||||
|
||||
<ol>
|
||||
<li> Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.</li>
|
||||
<li> The best attribute is selected and used as the test at the root node of the tree.</li>
|
||||
<li> A descendant of the root node is then created for each possible value of this attribute.</li>
|
||||
<li> Training examples are sorted to the appropriate descendant node.</li>
|
||||
<li> The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.</li>
|
||||
<li> This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.</li>
|
||||
</ol>
|
||||
|
||||
The ID3 algorithm selects, which attribute to test at each node in the
|
||||
tree.
|
||||
The example we will look at is a classical one in many Machine
|
||||
Learning applications. Based on various meteorological features, we
|
||||
have several so-called attributes which decide whether we at the end
|
||||
will do some outdoor activity like skiing, going for a bike ride etc
|
||||
etc. The table here contains the feautures <b>outlook</b>, <b>temperature</b>,
|
||||
<b>humidity</b> and <b>wind</b>. The target or output is whether we ride
|
||||
(True=1) or whether we do something else that day (False=0). The
|
||||
attributes for each feature are then sunny, overcast and rain for the
|
||||
outlook, hot, cold and mild for temperature, high and normal for
|
||||
humidity and weak and strong for wind.
|
||||
|
||||
<p>
|
||||
We would like to select the attribute that is most useful for classifying
|
||||
examples.
|
||||
|
||||
<p>
|
||||
What is a good quantitative measure of the worth of an attribute?
|
||||
|
||||
<p>
|
||||
Information gain measures how well a given attribute separates the
|
||||
training examples according to their target classification.
|
||||
|
||||
<p>
|
||||
The ID3 algorithm uses this information gain measure to select among the candidate
|
||||
attributes at each step while growing the tree.
|
||||
The table here summarizes the various attributes and
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-4">
|
||||
<table class="table table-striped table-hover table-condensed">
|
||||
<thead>
|
||||
<tr><td align="center"><b>Day</b></td> <td align="center"><b>Outlook </b></td> <td align="center"><b>Temperature</b></td> <td align="center"><b>Humidity</b></td> <td align="center"><b> Wind </b></td> <td align="center"><b>Ride</b></td> </tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td align="center"> 1 </td> <td align="center"> Sunny </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 2 </td> <td align="center"> Sunny </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 3 </td> <td align="center"> Overcast </td> <td align="center"> Hot </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 4 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 5 </td> <td align="center"> Rain </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 6 </td> <td align="center"> Rain </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 7 </td> <td align="center"> Overcast </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 8 </td> <td align="center"> Sunny </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Weak </td> <td align="center"> 0 </td> </tr>
|
||||
<tr><td align="center"> 9 </td> <td align="center"> Sunny </td> <td align="center"> Cool </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 10 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 11 </td> <td align="center"> Sunny </td> <td align="center"> Mild </td> <td align="center"> Normal </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 12 </td> <td align="center"> Overcast </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 13 </td> <td align="center"> Overcast </td> <td align="center"> Hot </td> <td align="center"> Normal </td> <td align="center"> Weak </td> <td align="center"> 1 </td> </tr>
|
||||
<tr><td align="center"> 14 </td> <td align="center"> Rain </td> <td align="center"> Mild </td> <td align="center"> High </td> <td align="center"> Strong </td> <td align="center"> 0 </td> </tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- col-xs-4 -->
|
||||
</div> <!-- cell row -->
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -260,7 +278,7 @@ attributes at each step while growing the tree.
|
||||
<li><a href="._week44-bs033.html">34</a></li>
|
||||
<li><a href="._week44-bs034.html">35</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs026.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,198 +210,78 @@ MathJax.Hub.Config({
|
||||
<a name="part0026"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec25" class="anchor">Implementing the ID3 Algorithm </h2>
|
||||
<h2 id="___sec25" class="anchor">Simple Python Code to read in Data and perform Classification </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">re</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">collections</span> <span style="color: #008000; font-weight: bold">import</span> deque
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Common imports</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
|
||||
<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.tree</span> <span style="color: #008000; font-weight: bold">import</span> export_graphviz
|
||||
<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, OneHotEncoder
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.compose</span> <span style="color: #008000; font-weight: bold">import</span> ColumnTransformer
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pydot</span> <span style="color: #008000; font-weight: bold">import</span> graph_from_dot_data
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># x is examples in training set</span>
|
||||
<span style="color: #408080; font-style: italic"># y is set of targets</span>
|
||||
<span style="color: #408080; font-style: italic"># label is target attributes</span>
|
||||
<span style="color: #408080; font-style: italic"># Node is a class which has properties values, childs, and next</span>
|
||||
<span style="color: #408080; font-style: italic"># root is top node in the decision tree</span>
|
||||
<span style="color: #408080; font-style: italic"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR <span style="color: #666666">=</span> <span style="color: #BA2121">"Results"</span>
|
||||
FIGURE_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"Results/FigureFiles"</span>
|
||||
DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">Node</span>(<span style="color: #008000">object</span>):
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">__init__</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>childs <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(PROJECT_ROOT_DIR):
|
||||
os<span style="color: #666666">.</span>mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Simple class of Decision Tree</span>
|
||||
<span style="color: #408080; font-style: italic"># Aimed for who want to learn Decision Tree, so it is not optimized</span>
|
||||
<span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">DecisionTree</span>(<span style="color: #008000">object</span>):
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">__init__</span>(<span style="color: #008000">self</span>, sample, attributes, labels):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>sample <span style="color: #666666">=</span> sample
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>attributes <span style="color: #666666">=</span> attributes
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labels <span style="color: #666666">=</span> labels
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>initLabelCodes()
|
||||
<span style="color: #408080; font-style: italic"># print(self.labelCodes)</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>root <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>entropy <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy([x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels))])
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(FIGURE_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">initLabelCodes</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> l <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels:
|
||||
<span style="color: #008000; font-weight: bold">if</span> l <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes:
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>append(l)
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount<span style="color: #666666">.</span>append(<span style="color: #666666">0</span>)
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(l)] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(DATA_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getLabelCodeId</span>(<span style="color: #008000">self</span>, sampleId):
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleId])
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">image_path</span>(fig_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getAttributeValues</span>(<span style="color: #008000">self</span>, sampleIds, attributeId):
|
||||
vals <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
val <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][attributeId]
|
||||
<span style="color: #008000; font-weight: bold">if</span> val <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> vals:
|
||||
vals<span style="color: #666666">.</span>append(val)
|
||||
<span style="color: #408080; font-style: italic"># print(vals)</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> vals
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">data_path</span>(dat_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getEntropy</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
entropy <span style="color: #666666">=</span> <span style="color: #666666">0</span>
|
||||
labelCount <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes)
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
labelCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>getLabelCodeId(sid)] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
<span style="color: #408080; font-style: italic"># print("-ge", labelCount)</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> lv <span style="color: #AA22FF; font-weight: bold">in</span> labelCount:
|
||||
<span style="color: #408080; font-style: italic"># print(lv)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> lv <span style="color: #666666">!=</span> <span style="color: #666666">0</span>:
|
||||
entropy <span style="color: #666666">+=</span> <span style="color: #666666">-</span>lv<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds) <span style="color: #666666">*</span> math<span style="color: #666666">.</span>log(lv<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds), <span style="color: #666666">2</span>)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
entropy <span style="color: #666666">+=</span> <span style="color: #666666">0</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> entropy
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
|
||||
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">".png"</span>, <span style="color: #008000">format</span><span style="color: #666666">=</span><span style="color: #BA2121">'png'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getDominantLabel</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
labelCodesCount <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes)
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
labelCodesCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sid])] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes[labelCodesCount<span style="color: #666666">.</span>index(<span style="color: #008000">max</span>(labelCodesCount))]
|
||||
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">"rideclass.csv"</span>),<span style="color: #BA2121">'r'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getInformationGain</span>(<span style="color: #008000">self</span>, sampleIds, attributeId):
|
||||
gain <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy(sampleIds)
|
||||
attributeVals <span style="color: #666666">=</span> []
|
||||
attributeValsCount <span style="color: #666666">=</span> []
|
||||
attributeValsIds <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
val <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][attributeId]
|
||||
<span style="color: #008000; font-weight: bold">if</span> val <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> attributeVals:
|
||||
attributeVals<span style="color: #666666">.</span>append(val)
|
||||
attributeValsCount<span style="color: #666666">.</span>append(<span style="color: #666666">0</span>)
|
||||
attributeValsIds<span style="color: #666666">.</span>append([])
|
||||
vid <span style="color: #666666">=</span> attributeVals<span style="color: #666666">.</span>index(val)
|
||||
attributeValsCount[vid] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
attributeValsIds[vid]<span style="color: #666666">.</span>append(sid)
|
||||
<span style="color: #408080; font-style: italic"># print("-gig", self.attributes[attributeId])</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> vc, vids <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">zip</span>(attributeValsCount, attributeValsIds):
|
||||
<span style="color: #408080; font-style: italic"># print("-gig", vids)</span>
|
||||
gain <span style="color: #666666">-=</span> vc<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds) <span style="color: #666666">*</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy(vids)
|
||||
<span style="color: #008000; font-weight: bold">return</span> gain
|
||||
<span style="color: #408080; font-style: italic"># Read the experimental data with Pandas</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
||||
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile,names <span style="color: #666666">=</span> (<span style="color: #BA2121">'Outlook'</span>,<span style="color: #BA2121">'Temperature'</span>,<span style="color: #BA2121">'Humidity'</span>,<span style="color: #BA2121">'Wind'</span>,<span style="color: #BA2121">'Ride'</span>))
|
||||
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(ridedata)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getAttributeMaxInformationGain</span>(<span style="color: #008000">self</span>, sampleIds, attributeIds):
|
||||
attributesEntropy <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(attributeIds)
|
||||
<span style="color: #008000; font-weight: bold">for</span> i, attId <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">zip</span>(<span style="color: #008000">range</span>(<span style="color: #008000">len</span>(attributeIds)), attributeIds):
|
||||
attributesEntropy[i] <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getInformationGain(sampleIds, attId)
|
||||
maxId <span style="color: #666666">=</span> attributeIds[attributesEntropy<span style="color: #666666">.</span>index(<span style="color: #008000">max</span>(attributesEntropy))]
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>attributes[maxId], maxId
|
||||
<span style="color: #408080; font-style: italic"># Features and targets</span>
|
||||
X <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">'Ride'</span>]<span style="color: #666666">.</span>values
|
||||
y <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">'Ride'</span>]<span style="color: #666666">.</span>values
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">isSingleLabeled</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
label <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleIds[<span style="color: #666666">0</span>]]
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sid] <span style="color: #666666">!=</span> label:
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000; font-weight: bold">False</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000; font-weight: bold">True</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getLabel</span>(<span style="color: #008000">self</span>, sampleId):
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleId]
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">id3</span>(<span style="color: #008000">self</span>):
|
||||
sampleIds <span style="color: #666666">=</span> [x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>sample))]
|
||||
attributeIds <span style="color: #666666">=</span> [x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>attributes))]
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>root <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>id3Recv(sampleIds, attributeIds, <span style="color: #008000">self</span><span style="color: #666666">.</span>root)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">id3Recv</span>(<span style="color: #008000">self</span>, sampleIds, attributeIds, root):
|
||||
root <span style="color: #666666">=</span> Node() <span style="color: #408080; font-style: italic"># Initialize current root</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>isSingleLabeled(sampleIds):
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleIds[<span style="color: #666666">0</span>]]
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
<span style="color: #408080; font-style: italic"># print(attributeIds)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(attributeIds) <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getDominantLabel(sampleIds)
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
bestAttrName, bestAttrId <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getAttributeMaxInformationGain(
|
||||
sampleIds, attributeIds)
|
||||
<span style="color: #408080; font-style: italic"># print(bestAttrName)</span>
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> bestAttrName
|
||||
root<span style="color: #666666">.</span>childs <span style="color: #666666">=</span> [] <span style="color: #408080; font-style: italic"># Create list of children</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> value <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getAttributeValues(sampleIds, bestAttrId):
|
||||
<span style="color: #408080; font-style: italic"># print(value)</span>
|
||||
child <span style="color: #666666">=</span> Node()
|
||||
child<span style="color: #666666">.</span>value <span style="color: #666666">=</span> value
|
||||
root<span style="color: #666666">.</span>childs<span style="color: #666666">.</span>append(child) <span style="color: #408080; font-style: italic"># Append new child node to current</span>
|
||||
<span style="color: #408080; font-style: italic"># root</span>
|
||||
childSampleIds <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][bestAttrId] <span style="color: #666666">==</span> value:
|
||||
childSampleIds<span style="color: #666666">.</span>append(sid)
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(childSampleIds) <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
child<span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getDominantLabel(sampleIds)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
<span style="color: #408080; font-style: italic"># print(bestAttrName, bestAttrId)</span>
|
||||
<span style="color: #408080; font-style: italic"># print(attributeIds)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(attributeIds) <span style="color: #666666">></span> <span style="color: #666666">0</span> <span style="color: #AA22FF; font-weight: bold">and</span> bestAttrId <span style="color: #AA22FF; font-weight: bold">in</span> attributeIds:
|
||||
toRemove <span style="color: #666666">=</span> attributeIds<span style="color: #666666">.</span>index(bestAttrId)
|
||||
attributeIds<span style="color: #666666">.</span>pop(toRemove)
|
||||
child<span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>id3Recv(
|
||||
childSampleIds, attributeIds, child<span style="color: #666666">.</span>next)
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">printTree</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>root:
|
||||
roots <span style="color: #666666">=</span> deque()
|
||||
roots<span style="color: #666666">.</span>append(<span style="color: #008000">self</span><span style="color: #666666">.</span>root)
|
||||
<span style="color: #008000; font-weight: bold">while</span> <span style="color: #008000">len</span>(roots) <span style="color: #666666">></span> <span style="color: #666666">0</span>:
|
||||
root <span style="color: #666666">=</span> roots<span style="color: #666666">.</span>popleft()
|
||||
<span style="color: #008000">print</span>(root<span style="color: #666666">.</span>value)
|
||||
<span style="color: #008000; font-weight: bold">if</span> root<span style="color: #666666">.</span>childs:
|
||||
<span style="color: #008000; font-weight: bold">for</span> child <span style="color: #AA22FF; font-weight: bold">in</span> root<span style="color: #666666">.</span>childs:
|
||||
<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: #666666">.</span>format(child<span style="color: #666666">.</span>value))
|
||||
roots<span style="color: #666666">.</span>append(child<span style="color: #666666">.</span>next)
|
||||
<span style="color: #008000; font-weight: bold">elif</span> root<span style="color: #666666">.</span>next:
|
||||
<span style="color: #008000">print</span>(root<span style="color: #666666">.</span>next)
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test</span>():
|
||||
f <span style="color: #666666">=</span> <span style="color: #008000">open</span>(<span style="color: #BA2121">'DataFiles/rideclass.csv'</span>)
|
||||
attributes <span style="color: #666666">=</span> f<span style="color: #666666">.</span>readline()<span style="color: #666666">.</span>split(<span style="color: #BA2121">','</span>)
|
||||
attributes <span style="color: #666666">=</span> attributes[<span style="color: #666666">1</span>:<span style="color: #008000">len</span>(attributes)<span style="color: #666666">-1</span>]
|
||||
<span style="color: #008000">print</span>(attributes)
|
||||
sample <span style="color: #666666">=</span> f<span style="color: #666666">.</span>readlines()
|
||||
f<span style="color: #666666">.</span>close()
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(sample)):
|
||||
sample[i] <span style="color: #666666">=</span> re<span style="color: #666666">.</span>sub(<span style="color: #BA2121">'\d+,'</span>, <span style="color: #BA2121">''</span>, sample[i])
|
||||
sample[i] <span style="color: #666666">=</span> sample[i]<span style="color: #666666">.</span>strip()<span style="color: #666666">.</span>split(<span style="color: #BA2121">','</span>)
|
||||
labels <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> s <span style="color: #AA22FF; font-weight: bold">in</span> sample:
|
||||
labels<span style="color: #666666">.</span>append(s<span style="color: #666666">.</span>pop())
|
||||
<span style="color: #408080; font-style: italic"># print(sample)</span>
|
||||
<span style="color: #408080; font-style: italic"># print(labels)</span>
|
||||
decisionTree <span style="color: #666666">=</span> DecisionTree(sample, attributes, labels)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"System entropy </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(decisionTree<span style="color: #666666">.</span>entropy))
|
||||
decisionTree<span style="color: #666666">.</span>id3()
|
||||
decisionTree<span style="color: #666666">.</span>printTree()
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #19177C">__name__</span> <span style="color: #666666">==</span> <span style="color: #BA2121">'__main__'</span>:
|
||||
test()
|
||||
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
|
||||
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">"ignore"</span>)
|
||||
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
|
||||
encoder<span style="color: #666666">.</span>fit(X)
|
||||
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
|
||||
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
|
||||
<span style="color: #008000">print</span>(X)
|
||||
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X, y)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Train set accuracy with Decision Tree: </span><span style="color: #BB6688; font-weight: bold">{:.2f}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(tree_clf<span style="color: #666666">.</span>score(X,y)))
|
||||
<span style="color: #408080; font-style: italic">#transfer to a decision tree graph</span>
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file<span style="color: #666666">=</span><span style="color: #BA2121">"DataFiles/ride.dot"</span>,
|
||||
rounded<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>,
|
||||
filled<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
@@ -420,7 +309,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs034.html">35</a></li>
|
||||
<li><a href="._week44-bs035.html">36</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs027.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,51 +210,80 @@ MathJax.Hub.Config({
|
||||
<a name="part0027"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec26" class="anchor">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<h2 id="___sec26" class="anchor">Computing the Gini Factor </h2>
|
||||
|
||||
<p>
|
||||
The above functions (gini, entropy and misclassification error) are
|
||||
important components of the so-called CART algorithm. We will discuss
|
||||
this algorithm below after we have discussed the information gain
|
||||
algorithm ID3.
|
||||
|
||||
<p>
|
||||
In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
|
||||
|
||||
<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">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
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Split a dataset based on an attribute and an attribute value</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_split</span>(index, value, dataset):
|
||||
left, right <span style="color: #666666">=</span> <span style="color: #008000">list</span>(), <span style="color: #008000">list</span>()
|
||||
<span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset:
|
||||
<span style="color: #008000; font-weight: bold">if</span> row[index] <span style="color: #666666"><</span> value:
|
||||
left<span style="color: #666666">.</span>append(row)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
right<span style="color: #666666">.</span>append(row)
|
||||
<span style="color: #008000; font-weight: bold">return</span> left, right
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Calculate the Gini index for a split dataset</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">gini_index</span>(groups, classes):
|
||||
<span style="color: #408080; font-style: italic"># count all samples at split point</span>
|
||||
n_instances <span style="color: #666666">=</span> <span style="color: #008000">float</span>(<span style="color: #008000">sum</span>([<span style="color: #008000">len</span>(group) <span style="color: #008000; font-weight: bold">for</span> group <span style="color: #AA22FF; font-weight: bold">in</span> groups]))
|
||||
<span style="color: #408080; font-style: italic"># sum weighted Gini index for each group</span>
|
||||
gini <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> group <span style="color: #AA22FF; font-weight: bold">in</span> groups:
|
||||
size <span style="color: #666666">=</span> <span style="color: #008000">float</span>(<span style="color: #008000">len</span>(group))
|
||||
<span style="color: #408080; font-style: italic"># avoid divide by zero</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> size <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
<span style="color: #008000; font-weight: bold">continue</span>
|
||||
score <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
<span style="color: #408080; font-style: italic"># score the group based on the score for each class</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> class_val <span style="color: #AA22FF; font-weight: bold">in</span> classes:
|
||||
p <span style="color: #666666">=</span> [row[<span style="color: #666666">-1</span>] <span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> group]<span style="color: #666666">.</span>count(class_val) <span style="color: #666666">/</span> size
|
||||
score <span style="color: #666666">+=</span> p <span style="color: #666666">*</span> p
|
||||
<span style="color: #408080; font-style: italic"># weight the group score by its relative size</span>
|
||||
gini <span style="color: #666666">+=</span> (<span style="color: #666666">1.0</span> <span style="color: #666666">-</span> score) <span style="color: #666666">*</span> (size <span style="color: #666666">/</span> n_instances)
|
||||
<span style="color: #008000; font-weight: bold">return</span> gini
|
||||
|
||||
<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"># Select the best split point for a dataset</span>
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">get_split</span>(dataset):
|
||||
class_values <span style="color: #666666">=</span> <span style="color: #008000">list</span>(<span style="color: #008000">set</span>(row[<span style="color: #666666">-1</span>] <span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset))
|
||||
b_index, b_value, b_score, b_groups <span style="color: #666666">=</span> <span style="color: #666666">999</span>, <span style="color: #666666">999</span>, <span style="color: #666666">999</span>, <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> index <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(dataset[<span style="color: #666666">0</span>])<span style="color: #666666">-1</span>):
|
||||
<span style="color: #008000; font-weight: bold">for</span> row <span style="color: #AA22FF; font-weight: bold">in</span> dataset:
|
||||
groups <span style="color: #666666">=</span> test_split(index, row[index], dataset)
|
||||
gini <span style="color: #666666">=</span> gini_index(groups, class_values)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'X</span><span style="color: #BB6688; font-weight: bold">%d</span><span style="color: #BA2121"> < </span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121"> Gini=</span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> ((index<span style="color: #666666">+1</span>), row[index], gini))
|
||||
<span style="color: #008000; font-weight: bold">if</span> gini <span style="color: #666666"><</span> b_score:
|
||||
b_index, b_value, b_score, b_groups <span style="color: #666666">=</span> index, row[index], gini, groups
|
||||
<span style="color: #008000; font-weight: bold">return</span> {<span style="color: #BA2121">'index'</span>:b_index, <span style="color: #BA2121">'value'</span>:b_value, <span style="color: #BA2121">'groups'</span>:b_groups}
|
||||
|
||||
dataset <span style="color: #666666">=</span> [[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>,<span style="color: #666666">0</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>],
|
||||
[<span style="color: #666666">2</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,<span style="color: #666666">0</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"># 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)))
|
||||
split <span style="color: #666666">=</span> get_split(dataset)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Split: [X</span><span style="color: #BB6688; font-weight: bold">%d</span><span style="color: #BA2121"> < </span><span style="color: #BB6688; font-weight: bold">%.3f</span><span style="color: #BA2121">]'</span> <span style="color: #666666">%</span> ((split[<span style="color: #BA2121">'index'</span>]<span style="color: #666666">+1</span>), split[<span style="color: #BA2121">'value'</span>]))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
@@ -273,7 +311,7 @@ deep_tree_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<li><a href="._week44-bs035.html">36</a></li>
|
||||
<li><a href="._week44-bs036.html">37</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs028.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,75 +210,39 @@ MathJax.Hub.Config({
|
||||
<a name="part0028"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec27" class="anchor">Another example, the moons again </h2>
|
||||
<h2 id="___sec27" class="anchor">Entropy and the ID3 algorithm </h2>
|
||||
|
||||
<p>
|
||||
ID3, learns decision trees by constructing
|
||||
them topdown, beginning with the question <b>which attribute should be tested at the root of the tree</b>?
|
||||
|
||||
<!-- 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">__future__</span> <span style="color: #008000; font-weight: bold">import</span> division, print_function, unicode_literals
|
||||
<ol>
|
||||
<li> Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.</li>
|
||||
<li> The best attribute is selected and used as the test at the root node of the tree.</li>
|
||||
<li> A descendant of the root node is then created for each possible value of this attribute.</li>
|
||||
<li> Training examples are sorted to the appropriate descendant node.</li>
|
||||
<li> The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.</li>
|
||||
<li> This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.</li>
|
||||
</ol>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Common imports</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
The ID3 algorithm selects, which attribute to test at each node in the
|
||||
tree.
|
||||
|
||||
<span style="color: #408080; font-style: italic"># to make this notebook's output stable across runs</span>
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
<p>
|
||||
We would like to select the attribute that is most useful for classifying
|
||||
examples.
|
||||
|
||||
<span style="color: #408080; font-style: italic"># To plot pretty figures</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib.colors</span> <span style="color: #008000; font-weight: bold">import</span> ListedColormap
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'axes.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">14</span>
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'xtick.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">12</span>
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'ytick.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">12</span>
|
||||
<p>
|
||||
What is a good quantitative measure of the worth of an attribute?
|
||||
|
||||
<p>
|
||||
Information gain measures how well a given attribute separates the
|
||||
training examples according to their target classification.
|
||||
|
||||
<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</span> <span style="color: #008000; font-weight: bold">import</span> datasets
|
||||
<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: #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> make_moons
|
||||
<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> export_graphviz
|
||||
<p>
|
||||
The ID3 algorithm uses this information gain measure to select among the candidate
|
||||
attributes at each step while growing the tree.
|
||||
|
||||
Xm, ym <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=100</span>, noise<span style="color: #666666">=0.25</span>, random_state<span style="color: #666666">=53</span>)
|
||||
|
||||
deep_tree_clf1 <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
deep_tree_clf2 <span style="color: #666666">=</span> DecisionTreeClassifier(min_samples_leaf<span style="color: #666666">=4</span>, random_state<span style="color: #666666">=42</span>)
|
||||
deep_tree_clf1<span style="color: #666666">.</span>fit(Xm, ym)
|
||||
deep_tree_clf2<span style="color: #666666">.</span>fit(Xm, ym)
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot_decision_boundary</span>(clf, X, y, axes<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, <span style="color: #666666">7.5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">3</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, legend<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>, plot_training<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>):
|
||||
x1s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">0</span>], axes[<span style="color: #666666">1</span>], <span style="color: #666666">100</span>)
|
||||
x2s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">2</span>], axes[<span style="color: #666666">3</span>], <span style="color: #666666">100</span>)
|
||||
x1, x2 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>meshgrid(x1s, x2s)
|
||||
X_new <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[x1<span style="color: #666666">.</span>ravel(), x2<span style="color: #666666">.</span>ravel()]
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_new)<span style="color: #666666">.</span>reshape(x1<span style="color: #666666">.</span>shape)
|
||||
custom_cmap <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#fafab0'</span>,<span style="color: #BA2121">'#9898ff'</span>,<span style="color: #BA2121">'#a0faa0'</span>])
|
||||
plt<span style="color: #666666">.</span>contourf(x1, x2, y_pred, alpha<span style="color: #666666">=0.3</span>, cmap<span style="color: #666666">=</span>custom_cmap)
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> iris:
|
||||
custom_cmap2 <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#7d7d58'</span>,<span style="color: #BA2121">'#4c4c7f'</span>,<span style="color: #BA2121">'#507d50'</span>])
|
||||
plt<span style="color: #666666">.</span>contour(x1, x2, y_pred, cmap<span style="color: #666666">=</span>custom_cmap2, alpha<span style="color: #666666">=0.8</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> plot_training:
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==0</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==0</span>], <span style="color: #BA2121">"yo"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Setosa"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==1</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==1</span>], <span style="color: #BA2121">"bs"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Versicolor"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==2</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==2</span>], <span style="color: #BA2121">"g^"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Virginica"</span>)
|
||||
plt<span style="color: #666666">.</span>axis(axes)
|
||||
<span style="color: #008000; font-weight: bold">if</span> iris:
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Petal length"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Petal width"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r"$x_2$"</span>, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> legend:
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"lower right"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_decision_boundary(deep_tree_clf1, Xm, ym, axes<span style="color: #666666">=</span>[<span style="color: #666666">-1.5</span>, <span style="color: #666666">2.5</span>, <span style="color: #666666">-1</span>, <span style="color: #666666">1.5</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"No restrictions"</span>, fontsize<span style="color: #666666">=16</span>)
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_decision_boundary(deep_tree_clf2, Xm, ym, axes<span style="color: #666666">=</span>[<span style="color: #666666">-1.5</span>, <span style="color: #666666">2.5</span>, <span style="color: #666666">-1</span>, <span style="color: #666666">1.5</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"min_samples_leaf = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf2<span style="color: #666666">.</span>min_samples_leaf), fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -296,7 +269,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs036.html">37</a></li>
|
||||
<li><a href="._week44-bs037.html">38</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs029.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,30 +210,198 @@ MathJax.Hub.Config({
|
||||
<a name="part0029"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec28" class="anchor">Playing around with regions </h2>
|
||||
<h2 id="___sec28" class="anchor">Implementing the ID3 Algorithm </h2>
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">6</span>)
|
||||
Xs <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>, <span style="color: #666666">2</span>) <span style="color: #666666">-</span> <span style="color: #666666">0.5</span>
|
||||
ys <span style="color: #666666">=</span> (Xs[:, <span style="color: #666666">0</span>] <span style="color: #666666">></span> <span style="color: #666666">0</span>)<span style="color: #666666">.</span>astype(np<span style="color: #666666">.</span>float32) <span style="color: #666666">*</span> <span style="color: #666666">2</span>
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">re</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">collections</span> <span style="color: #008000; font-weight: bold">import</span> deque
|
||||
|
||||
angle <span style="color: #666666">=</span> np<span style="color: #666666">.</span>pi<span style="color: #666666">/4</span>
|
||||
rotation_matrix <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[np<span style="color: #666666">.</span>cos(angle), <span style="color: #666666">-</span>np<span style="color: #666666">.</span>sin(angle)], [np<span style="color: #666666">.</span>sin(angle), np<span style="color: #666666">.</span>cos(angle)]])
|
||||
Xsr <span style="color: #666666">=</span> Xs<span style="color: #666666">.</span>dot(rotation_matrix)
|
||||
<span style="color: #408080; font-style: italic"># x is examples in training set</span>
|
||||
<span style="color: #408080; font-style: italic"># y is set of targets</span>
|
||||
<span style="color: #408080; font-style: italic"># label is target attributes</span>
|
||||
<span style="color: #408080; font-style: italic"># Node is a class which has properties values, childs, and next</span>
|
||||
<span style="color: #408080; font-style: italic"># root is top node in the decision tree</span>
|
||||
|
||||
tree_clf_s <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
tree_clf_s<span style="color: #666666">.</span>fit(Xs, ys)
|
||||
tree_clf_sr <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
tree_clf_sr<span style="color: #666666">.</span>fit(Xsr, ys)
|
||||
<span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">Node</span>(<span style="color: #008000">object</span>):
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">__init__</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>childs <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_decision_boundary(tree_clf_s, Xs, ys, axes<span style="color: #666666">=</span>[<span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>, <span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_decision_boundary(tree_clf_sr, Xsr, ys, axes<span style="color: #666666">=</span>[<span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>, <span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
<span style="color: #408080; font-style: italic"># Simple class of Decision Tree</span>
|
||||
<span style="color: #408080; font-style: italic"># Aimed for who want to learn Decision Tree, so it is not optimized</span>
|
||||
<span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">DecisionTree</span>(<span style="color: #008000">object</span>):
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">__init__</span>(<span style="color: #008000">self</span>, sample, attributes, labels):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>sample <span style="color: #666666">=</span> sample
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>attributes <span style="color: #666666">=</span> attributes
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labels <span style="color: #666666">=</span> labels
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>initLabelCodes()
|
||||
<span style="color: #408080; font-style: italic"># print(self.labelCodes)</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>root <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">None</span>
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>entropy <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy([x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels))])
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">initLabelCodes</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> l <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels:
|
||||
<span style="color: #008000; font-weight: bold">if</span> l <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes:
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>append(l)
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount<span style="color: #666666">.</span>append(<span style="color: #666666">0</span>)
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodesCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(l)] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getLabelCodeId</span>(<span style="color: #008000">self</span>, sampleId):
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleId])
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getAttributeValues</span>(<span style="color: #008000">self</span>, sampleIds, attributeId):
|
||||
vals <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
val <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][attributeId]
|
||||
<span style="color: #008000; font-weight: bold">if</span> val <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> vals:
|
||||
vals<span style="color: #666666">.</span>append(val)
|
||||
<span style="color: #408080; font-style: italic"># print(vals)</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> vals
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getEntropy</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
entropy <span style="color: #666666">=</span> <span style="color: #666666">0</span>
|
||||
labelCount <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes)
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
labelCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>getLabelCodeId(sid)] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
<span style="color: #408080; font-style: italic"># print("-ge", labelCount)</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> lv <span style="color: #AA22FF; font-weight: bold">in</span> labelCount:
|
||||
<span style="color: #408080; font-style: italic"># print(lv)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> lv <span style="color: #666666">!=</span> <span style="color: #666666">0</span>:
|
||||
entropy <span style="color: #666666">+=</span> <span style="color: #666666">-</span>lv<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds) <span style="color: #666666">*</span> math<span style="color: #666666">.</span>log(lv<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds), <span style="color: #666666">2</span>)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
entropy <span style="color: #666666">+=</span> <span style="color: #666666">0</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> entropy
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getDominantLabel</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
labelCodesCount <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes)
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
labelCodesCount[<span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes<span style="color: #666666">.</span>index(<span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sid])] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labelCodes[labelCodesCount<span style="color: #666666">.</span>index(<span style="color: #008000">max</span>(labelCodesCount))]
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getInformationGain</span>(<span style="color: #008000">self</span>, sampleIds, attributeId):
|
||||
gain <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy(sampleIds)
|
||||
attributeVals <span style="color: #666666">=</span> []
|
||||
attributeValsCount <span style="color: #666666">=</span> []
|
||||
attributeValsIds <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
val <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][attributeId]
|
||||
<span style="color: #008000; font-weight: bold">if</span> val <span style="color: #AA22FF; font-weight: bold">not</span> <span style="color: #AA22FF; font-weight: bold">in</span> attributeVals:
|
||||
attributeVals<span style="color: #666666">.</span>append(val)
|
||||
attributeValsCount<span style="color: #666666">.</span>append(<span style="color: #666666">0</span>)
|
||||
attributeValsIds<span style="color: #666666">.</span>append([])
|
||||
vid <span style="color: #666666">=</span> attributeVals<span style="color: #666666">.</span>index(val)
|
||||
attributeValsCount[vid] <span style="color: #666666">+=</span> <span style="color: #666666">1</span>
|
||||
attributeValsIds[vid]<span style="color: #666666">.</span>append(sid)
|
||||
<span style="color: #408080; font-style: italic"># print("-gig", self.attributes[attributeId])</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> vc, vids <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">zip</span>(attributeValsCount, attributeValsIds):
|
||||
<span style="color: #408080; font-style: italic"># print("-gig", vids)</span>
|
||||
gain <span style="color: #666666">-=</span> vc<span style="color: #666666">/</span><span style="color: #008000">len</span>(sampleIds) <span style="color: #666666">*</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getEntropy(vids)
|
||||
<span style="color: #008000; font-weight: bold">return</span> gain
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getAttributeMaxInformationGain</span>(<span style="color: #008000">self</span>, sampleIds, attributeIds):
|
||||
attributesEntropy <span style="color: #666666">=</span> [<span style="color: #666666">0</span>] <span style="color: #666666">*</span> <span style="color: #008000">len</span>(attributeIds)
|
||||
<span style="color: #008000; font-weight: bold">for</span> i, attId <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">zip</span>(<span style="color: #008000">range</span>(<span style="color: #008000">len</span>(attributeIds)), attributeIds):
|
||||
attributesEntropy[i] <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getInformationGain(sampleIds, attId)
|
||||
maxId <span style="color: #666666">=</span> attributeIds[attributesEntropy<span style="color: #666666">.</span>index(<span style="color: #008000">max</span>(attributesEntropy))]
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>attributes[maxId], maxId
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">isSingleLabeled</span>(<span style="color: #008000">self</span>, sampleIds):
|
||||
label <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleIds[<span style="color: #666666">0</span>]]
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sid] <span style="color: #666666">!=</span> label:
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000; font-weight: bold">False</span>
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000; font-weight: bold">True</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getLabel</span>(<span style="color: #008000">self</span>, sampleId):
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleId]
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">id3</span>(<span style="color: #008000">self</span>):
|
||||
sampleIds <span style="color: #666666">=</span> [x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>sample))]
|
||||
attributeIds <span style="color: #666666">=</span> [x <span style="color: #008000; font-weight: bold">for</span> x <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(<span style="color: #008000">self</span><span style="color: #666666">.</span>attributes))]
|
||||
<span style="color: #008000">self</span><span style="color: #666666">.</span>root <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>id3Recv(sampleIds, attributeIds, <span style="color: #008000">self</span><span style="color: #666666">.</span>root)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">id3Recv</span>(<span style="color: #008000">self</span>, sampleIds, attributeIds, root):
|
||||
root <span style="color: #666666">=</span> Node() <span style="color: #408080; font-style: italic"># Initialize current root</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>isSingleLabeled(sampleIds):
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>labels[sampleIds[<span style="color: #666666">0</span>]]
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
<span style="color: #408080; font-style: italic"># print(attributeIds)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(attributeIds) <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getDominantLabel(sampleIds)
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
bestAttrName, bestAttrId <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getAttributeMaxInformationGain(
|
||||
sampleIds, attributeIds)
|
||||
<span style="color: #408080; font-style: italic"># print(bestAttrName)</span>
|
||||
root<span style="color: #666666">.</span>value <span style="color: #666666">=</span> bestAttrName
|
||||
root<span style="color: #666666">.</span>childs <span style="color: #666666">=</span> [] <span style="color: #408080; font-style: italic"># Create list of children</span>
|
||||
<span style="color: #008000; font-weight: bold">for</span> value <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getAttributeValues(sampleIds, bestAttrId):
|
||||
<span style="color: #408080; font-style: italic"># print(value)</span>
|
||||
child <span style="color: #666666">=</span> Node()
|
||||
child<span style="color: #666666">.</span>value <span style="color: #666666">=</span> value
|
||||
root<span style="color: #666666">.</span>childs<span style="color: #666666">.</span>append(child) <span style="color: #408080; font-style: italic"># Append new child node to current</span>
|
||||
<span style="color: #408080; font-style: italic"># root</span>
|
||||
childSampleIds <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> sid <span style="color: #AA22FF; font-weight: bold">in</span> sampleIds:
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>sample[sid][bestAttrId] <span style="color: #666666">==</span> value:
|
||||
childSampleIds<span style="color: #666666">.</span>append(sid)
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(childSampleIds) <span style="color: #666666">==</span> <span style="color: #666666">0</span>:
|
||||
child<span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>getDominantLabel(sampleIds)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
<span style="color: #408080; font-style: italic"># print(bestAttrName, bestAttrId)</span>
|
||||
<span style="color: #408080; font-style: italic"># print(attributeIds)</span>
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(attributeIds) <span style="color: #666666">></span> <span style="color: #666666">0</span> <span style="color: #AA22FF; font-weight: bold">and</span> bestAttrId <span style="color: #AA22FF; font-weight: bold">in</span> attributeIds:
|
||||
toRemove <span style="color: #666666">=</span> attributeIds<span style="color: #666666">.</span>index(bestAttrId)
|
||||
attributeIds<span style="color: #666666">.</span>pop(toRemove)
|
||||
child<span style="color: #666666">.</span>next <span style="color: #666666">=</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>id3Recv(
|
||||
childSampleIds, attributeIds, child<span style="color: #666666">.</span>next)
|
||||
<span style="color: #008000; font-weight: bold">return</span> root
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">printTree</span>(<span style="color: #008000">self</span>):
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">self</span><span style="color: #666666">.</span>root:
|
||||
roots <span style="color: #666666">=</span> deque()
|
||||
roots<span style="color: #666666">.</span>append(<span style="color: #008000">self</span><span style="color: #666666">.</span>root)
|
||||
<span style="color: #008000; font-weight: bold">while</span> <span style="color: #008000">len</span>(roots) <span style="color: #666666">></span> <span style="color: #666666">0</span>:
|
||||
root <span style="color: #666666">=</span> roots<span style="color: #666666">.</span>popleft()
|
||||
<span style="color: #008000">print</span>(root<span style="color: #666666">.</span>value)
|
||||
<span style="color: #008000; font-weight: bold">if</span> root<span style="color: #666666">.</span>childs:
|
||||
<span style="color: #008000; font-weight: bold">for</span> child <span style="color: #AA22FF; font-weight: bold">in</span> root<span style="color: #666666">.</span>childs:
|
||||
<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: #666666">.</span>format(child<span style="color: #666666">.</span>value))
|
||||
roots<span style="color: #666666">.</span>append(child<span style="color: #666666">.</span>next)
|
||||
<span style="color: #008000; font-weight: bold">elif</span> root<span style="color: #666666">.</span>next:
|
||||
<span style="color: #008000">print</span>(root<span style="color: #666666">.</span>next)
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test</span>():
|
||||
f <span style="color: #666666">=</span> <span style="color: #008000">open</span>(<span style="color: #BA2121">'DataFiles/rideclass.csv'</span>)
|
||||
attributes <span style="color: #666666">=</span> f<span style="color: #666666">.</span>readline()<span style="color: #666666">.</span>split(<span style="color: #BA2121">','</span>)
|
||||
attributes <span style="color: #666666">=</span> attributes[<span style="color: #666666">1</span>:<span style="color: #008000">len</span>(attributes)<span style="color: #666666">-1</span>]
|
||||
<span style="color: #008000">print</span>(attributes)
|
||||
sample <span style="color: #666666">=</span> f<span style="color: #666666">.</span>readlines()
|
||||
f<span style="color: #666666">.</span>close()
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(sample)):
|
||||
sample[i] <span style="color: #666666">=</span> re<span style="color: #666666">.</span>sub(<span style="color: #BA2121">'\d+,'</span>, <span style="color: #BA2121">''</span>, sample[i])
|
||||
sample[i] <span style="color: #666666">=</span> sample[i]<span style="color: #666666">.</span>strip()<span style="color: #666666">.</span>split(<span style="color: #BA2121">','</span>)
|
||||
labels <span style="color: #666666">=</span> []
|
||||
<span style="color: #008000; font-weight: bold">for</span> s <span style="color: #AA22FF; font-weight: bold">in</span> sample:
|
||||
labels<span style="color: #666666">.</span>append(s<span style="color: #666666">.</span>pop())
|
||||
<span style="color: #408080; font-style: italic"># print(sample)</span>
|
||||
<span style="color: #408080; font-style: italic"># print(labels)</span>
|
||||
decisionTree <span style="color: #666666">=</span> DecisionTree(sample, attributes, labels)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"System entropy </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(decisionTree<span style="color: #666666">.</span>entropy))
|
||||
decisionTree<span style="color: #666666">.</span>id3()
|
||||
decisionTree<span style="color: #666666">.</span>printTree()
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #19177C">__name__</span> <span style="color: #666666">==</span> <span style="color: #BA2121">'__main__'</span>:
|
||||
test()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
@@ -252,7 +429,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs037.html">38</a></li>
|
||||
<li><a href="._week44-bs038.html">39</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs030.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,24 +210,51 @@ MathJax.Hub.Config({
|
||||
<a name="part0030"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec29" class="anchor">Regression trees </h2>
|
||||
<h2 id="___sec29" class="anchor">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Quadratic training set + noise</span>
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
m <span style="color: #666666">=</span> <span style="color: #666666">200</span>
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(m, <span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4</span> <span style="color: #666666">*</span> (X <span style="color: #666666">-</span> <span style="color: #666666">0.5</span>) <span style="color: #666666">**</span> <span style="color: #666666">2</span>
|
||||
y <span style="color: #666666">=</span> y <span style="color: #666666">+</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(m, <span style="color: #666666">1</span>) <span style="color: #666666">/</span> <span style="color: #666666">10</span>
|
||||
</pre></div>
|
||||
<p>
|
||||
<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
|
||||
|
||||
<!-- 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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
<span style="color: #408080; font-style: italic"># Load the data</span>
|
||||
cancer <span style="color: #666666">=</span> load_breast_cancer()
|
||||
|
||||
tree_reg <span style="color: #666666">=</span> DecisionTreeRegressor(max_depth<span style="color: #666666">=2</span>, random_state<span style="color: #666666">=42</span>)
|
||||
tree_reg<span style="color: #666666">.</span>fit(X, y)
|
||||
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)))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
@@ -246,7 +282,7 @@ tree_reg<span style="color: #666666">.</span>fit(X, y)
|
||||
<li><a href="._week44-bs038.html">39</a></li>
|
||||
<li><a href="._week44-bs039.html">40</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs031.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,79 +210,73 @@ MathJax.Hub.Config({
|
||||
<a name="part0031"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec30" class="anchor">Final regressor code </h2>
|
||||
<h2 id="___sec30" class="anchor">Another example, the moons again </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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
<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">__future__</span> <span style="color: #008000; font-weight: bold">import</span> division, print_function, unicode_literals
|
||||
|
||||
tree_reg1 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, max_depth<span style="color: #666666">=2</span>)
|
||||
tree_reg2 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, max_depth<span style="color: #666666">=3</span>)
|
||||
tree_reg1<span style="color: #666666">.</span>fit(X, y)
|
||||
tree_reg2<span style="color: #666666">.</span>fit(X, y)
|
||||
<span style="color: #408080; font-style: italic"># Common imports</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot_regression_predictions</span>(tree_reg, X, y, axes<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], ylabel<span style="color: #666666">=</span><span style="color: #BA2121">"$y$"</span>):
|
||||
x1 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">0</span>], axes[<span style="color: #666666">1</span>], <span style="color: #666666">500</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
y_pred <span style="color: #666666">=</span> tree_reg<span style="color: #666666">.</span>predict(x1)
|
||||
plt<span style="color: #666666">.</span>axis(axes)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> ylabel:
|
||||
plt<span style="color: #666666">.</span>ylabel(ylabel, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
<span style="color: #408080; font-style: italic"># to make this notebook's output stable across runs</span>
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># To plot pretty figures</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib.colors</span> <span style="color: #008000; font-weight: bold">import</span> ListedColormap
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'axes.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">14</span>
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'xtick.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">12</span>
|
||||
plt<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'ytick.labelsize'</span>] <span style="color: #666666">=</span> <span style="color: #666666">12</span>
|
||||
|
||||
|
||||
<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</span> <span style="color: #008000; font-weight: bold">import</span> datasets
|
||||
<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: #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> make_moons
|
||||
<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> export_graphviz
|
||||
|
||||
Xm, ym <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=100</span>, noise<span style="color: #666666">=0.25</span>, random_state<span style="color: #666666">=53</span>)
|
||||
|
||||
deep_tree_clf1 <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
deep_tree_clf2 <span style="color: #666666">=</span> DecisionTreeClassifier(min_samples_leaf<span style="color: #666666">=4</span>, random_state<span style="color: #666666">=42</span>)
|
||||
deep_tree_clf1<span style="color: #666666">.</span>fit(Xm, ym)
|
||||
deep_tree_clf2<span style="color: #666666">.</span>fit(Xm, ym)
|
||||
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot_decision_boundary</span>(clf, X, y, axes<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, <span style="color: #666666">7.5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">3</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, legend<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>, plot_training<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>):
|
||||
x1s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">0</span>], axes[<span style="color: #666666">1</span>], <span style="color: #666666">100</span>)
|
||||
x2s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">2</span>], axes[<span style="color: #666666">3</span>], <span style="color: #666666">100</span>)
|
||||
x1, x2 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>meshgrid(x1s, x2s)
|
||||
X_new <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[x1<span style="color: #666666">.</span>ravel(), x2<span style="color: #666666">.</span>ravel()]
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_new)<span style="color: #666666">.</span>reshape(x1<span style="color: #666666">.</span>shape)
|
||||
custom_cmap <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#fafab0'</span>,<span style="color: #BA2121">'#9898ff'</span>,<span style="color: #BA2121">'#a0faa0'</span>])
|
||||
plt<span style="color: #666666">.</span>contourf(x1, x2, y_pred, alpha<span style="color: #666666">=0.3</span>, cmap<span style="color: #666666">=</span>custom_cmap)
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> iris:
|
||||
custom_cmap2 <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#7d7d58'</span>,<span style="color: #BA2121">'#4c4c7f'</span>,<span style="color: #BA2121">'#507d50'</span>])
|
||||
plt<span style="color: #666666">.</span>contour(x1, x2, y_pred, cmap<span style="color: #666666">=</span>custom_cmap2, alpha<span style="color: #666666">=0.8</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> plot_training:
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==0</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==0</span>], <span style="color: #BA2121">"yo"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Setosa"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==1</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==1</span>], <span style="color: #BA2121">"bs"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Versicolor"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==2</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==2</span>], <span style="color: #BA2121">"g^"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"Iris-Virginica"</span>)
|
||||
plt<span style="color: #666666">.</span>axis(axes)
|
||||
<span style="color: #008000; font-weight: bold">if</span> iris:
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Petal length"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Petal width"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
<span style="color: #008000; font-weight: bold">else</span>:
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r"$x_2$"</span>, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> legend:
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"lower right"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_regression_predictions(tree_reg1, X, y)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split, style <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">0.1973</span>, <span style="color: #BA2121">"k-"</span>), (<span style="color: #666666">0.0917</span>, <span style="color: #BA2121">"k--"</span>), (<span style="color: #666666">0.7718</span>, <span style="color: #BA2121">"k--"</span>)):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], style, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.21</span>, <span style="color: #666666">0.65</span>, <span style="color: #BA2121">"Depth=0"</span>, fontsize<span style="color: #666666">=15</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.01</span>, <span style="color: #666666">0.2</span>, <span style="color: #BA2121">"Depth=1"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.65</span>, <span style="color: #666666">0.8</span>, <span style="color: #BA2121">"Depth=1"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"upper center"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"max_depth=2"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plot_decision_boundary(deep_tree_clf1, Xm, ym, axes<span style="color: #666666">=</span>[<span style="color: #666666">-1.5</span>, <span style="color: #666666">2.5</span>, <span style="color: #666666">-1</span>, <span style="color: #666666">1.5</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"No restrictions"</span>, fontsize<span style="color: #666666">=16</span>)
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_regression_predictions(tree_reg2, X, y, ylabel<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">None</span>)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split, style <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">0.1973</span>, <span style="color: #BA2121">"k-"</span>), (<span style="color: #666666">0.0917</span>, <span style="color: #BA2121">"k--"</span>), (<span style="color: #666666">0.7718</span>, <span style="color: #BA2121">"k--"</span>)):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], style, linewidth<span style="color: #666666">=2</span>)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split <span style="color: #AA22FF; font-weight: bold">in</span> (<span style="color: #666666">0.0458</span>, <span style="color: #666666">0.1298</span>, <span style="color: #666666">0.2873</span>, <span style="color: #666666">0.9040</span>):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], <span style="color: #BA2121">"k:"</span>, linewidth<span style="color: #666666">=1</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.3</span>, <span style="color: #666666">0.5</span>, <span style="color: #BA2121">"Depth=2"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"max_depth=3"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>tree_reg1 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>)
|
||||
tree_reg2 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, min_samples_leaf<span style="color: #666666">=10</span>)
|
||||
tree_reg1<span style="color: #666666">.</span>fit(X, y)
|
||||
tree_reg2<span style="color: #666666">.</span>fit(X, y)
|
||||
|
||||
x1 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">500</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
y_pred1 <span style="color: #666666">=</span> tree_reg1<span style="color: #666666">.</span>predict(x1)
|
||||
y_pred2 <span style="color: #666666">=</span> tree_reg2<span style="color: #666666">.</span>predict(x1)
|
||||
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred1, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1.1</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"upper center"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"No restrictions"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred2, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1.1</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"min_samples_leaf=</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(tree_reg2<span style="color: #666666">.</span>min_samples_leaf), fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plot_decision_boundary(deep_tree_clf2, Xm, ym, axes<span style="color: #666666">=</span>[<span style="color: #666666">-1.5</span>, <span style="color: #666666">2.5</span>, <span style="color: #666666">-1</span>, <span style="color: #666666">1.5</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"min_samples_leaf = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(deep_tree_clf2<span style="color: #666666">.</span>min_samples_leaf), fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -302,7 +305,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs039.html">40</a></li>
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs032.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,18 +210,32 @@ MathJax.Hub.Config({
|
||||
<a name="part0032"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec31" class="anchor">Pros and cons of trees, pros </h2>
|
||||
<h2 id="___sec31" class="anchor">Playing around with regions </h2>
|
||||
<p>
|
||||
|
||||
<ul>
|
||||
<li> White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)</li>
|
||||
<li> Trees are very easy to explain to people. In fact, they are even easier to explain than linear regression!</li>
|
||||
<li> No feature normalization needed</li>
|
||||
<li> Tree models can handle both continuous and categorical data (Classification and Regression Trees)</li>
|
||||
<li> Can model nonlinear relationships</li>
|
||||
<li> Can model interactions between the different descriptive features</li>
|
||||
<li> Trees can be displayed graphically, and are easily interpreted even by a non-expert (especially if they are small)</li>
|
||||
</ul>
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">6</span>)
|
||||
Xs <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>, <span style="color: #666666">2</span>) <span style="color: #666666">-</span> <span style="color: #666666">0.5</span>
|
||||
ys <span style="color: #666666">=</span> (Xs[:, <span style="color: #666666">0</span>] <span style="color: #666666">></span> <span style="color: #666666">0</span>)<span style="color: #666666">.</span>astype(np<span style="color: #666666">.</span>float32) <span style="color: #666666">*</span> <span style="color: #666666">2</span>
|
||||
|
||||
angle <span style="color: #666666">=</span> np<span style="color: #666666">.</span>pi<span style="color: #666666">/4</span>
|
||||
rotation_matrix <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[np<span style="color: #666666">.</span>cos(angle), <span style="color: #666666">-</span>np<span style="color: #666666">.</span>sin(angle)], [np<span style="color: #666666">.</span>sin(angle), np<span style="color: #666666">.</span>cos(angle)]])
|
||||
Xsr <span style="color: #666666">=</span> Xs<span style="color: #666666">.</span>dot(rotation_matrix)
|
||||
|
||||
tree_clf_s <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
tree_clf_s<span style="color: #666666">.</span>fit(Xs, ys)
|
||||
tree_clf_sr <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
tree_clf_sr<span style="color: #666666">.</span>fit(Xsr, ys)
|
||||
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_decision_boundary(tree_clf_s, Xs, ys, axes<span style="color: #666666">=</span>[<span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>, <span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_decision_boundary(tree_clf_sr, Xsr, ys, axes<span style="color: #666666">=</span>[<span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>, <span style="color: #666666">-0.7</span>, <span style="color: #666666">0.7</span>], iris<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -238,7 +261,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs033.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,22 +210,25 @@ MathJax.Hub.Config({
|
||||
<a name="part0033"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec32" class="anchor">Disadvantages </h2>
|
||||
<h2 id="___sec32" class="anchor">Regression trees </h2>
|
||||
<p>
|
||||
|
||||
<ul>
|
||||
<li> Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches</li>
|
||||
<li> If continuous features are used the tree may become quite large and hence less interpretable</li>
|
||||
<li> Decision trees are prone to overfit the training data and hence do not well generalize the data if no stopping criteria or improvements like pruning, boosting or bagging are implemented</li>
|
||||
<li> Small changes in the data may lead to a completely different tree. This issue can be addressed by using ensemble methods like bagging, boosting or random forests</li>
|
||||
<li> Unbalanced datasets where some target feature values occur much more frequently than others may lead to biased trees since the frequently occurring feature values are preferred over the less frequently occurring ones.</li>
|
||||
<li> If the number of features is relatively large (high dimensional) and the number of instances is relatively low, the tree might overfit the data</li>
|
||||
<li> Features with many levels may be preferred over features with less levels since for them it is <em>more easy</em> to split the dataset such that the sub datasets only contain pure target feature values. This issue can be addressed by preferring for instance the information gain ratio as splitting criteria over information gain</li>
|
||||
</ul>
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Quadratic training set + noise</span>
|
||||
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">42</span>)
|
||||
m <span style="color: #666666">=</span> <span style="color: #666666">200</span>
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(m, <span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4</span> <span style="color: #666666">*</span> (X <span style="color: #666666">-</span> <span style="color: #666666">0.5</span>) <span style="color: #666666">**</span> <span style="color: #666666">2</span>
|
||||
y <span style="color: #666666">=</span> y <span style="color: #666666">+</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(m, <span style="color: #666666">1</span>) <span style="color: #666666">/</span> <span style="color: #666666">10</span>
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
However, by aggregating many decision trees, using methods like
|
||||
bagging, random forests, and boosting, the predictive performance of
|
||||
trees can be substantially improved.
|
||||
<!-- 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.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
|
||||
tree_reg <span style="color: #666666">=</span> DecisionTreeRegressor(max_depth<span style="color: #666666">=2</span>, random_state<span style="color: #666666">=42</span>)
|
||||
tree_reg<span style="color: #666666">.</span>fit(X, y)
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -242,6 +254,8 @@ trees can be substantially improved.
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs034.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,30 +210,81 @@ MathJax.Hub.Config({
|
||||
<a name="part0034"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec33" class="anchor">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
|
||||
<h2 id="___sec33" class="anchor">Final regressor code </h2>
|
||||
<p>
|
||||
As stated above and seen in many of the examples discussed here about
|
||||
a single decision tree, we often end up overfitting our training
|
||||
data. This normally means that we have a high variance. Can we reduce
|
||||
the variance of a statistical learning method?
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
|
||||
tree_reg1 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, max_depth<span style="color: #666666">=2</span>)
|
||||
tree_reg2 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, max_depth<span style="color: #666666">=3</span>)
|
||||
tree_reg1<span style="color: #666666">.</span>fit(X, y)
|
||||
tree_reg2<span style="color: #666666">.</span>fit(X, y)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot_regression_predictions</span>(tree_reg, X, y, axes<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], ylabel<span style="color: #666666">=</span><span style="color: #BA2121">"$y$"</span>):
|
||||
x1 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">0</span>], axes[<span style="color: #666666">1</span>], <span style="color: #666666">500</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
y_pred <span style="color: #666666">=</span> tree_reg<span style="color: #666666">.</span>predict(x1)
|
||||
plt<span style="color: #666666">.</span>axis(axes)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
<span style="color: #008000; font-weight: bold">if</span> ylabel:
|
||||
plt<span style="color: #666666">.</span>ylabel(ylabel, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_regression_predictions(tree_reg1, X, y)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split, style <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">0.1973</span>, <span style="color: #BA2121">"k-"</span>), (<span style="color: #666666">0.0917</span>, <span style="color: #BA2121">"k--"</span>), (<span style="color: #666666">0.7718</span>, <span style="color: #BA2121">"k--"</span>)):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], style, linewidth<span style="color: #666666">=2</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.21</span>, <span style="color: #666666">0.65</span>, <span style="color: #BA2121">"Depth=0"</span>, fontsize<span style="color: #666666">=15</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.01</span>, <span style="color: #666666">0.2</span>, <span style="color: #BA2121">"Depth=1"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.65</span>, <span style="color: #666666">0.8</span>, <span style="color: #BA2121">"Depth=1"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"upper center"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"max_depth=2"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_regression_predictions(tree_reg2, X, y, ylabel<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">None</span>)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split, style <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">0.1973</span>, <span style="color: #BA2121">"k-"</span>), (<span style="color: #666666">0.0917</span>, <span style="color: #BA2121">"k--"</span>), (<span style="color: #666666">0.7718</span>, <span style="color: #BA2121">"k--"</span>)):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], style, linewidth<span style="color: #666666">=2</span>)
|
||||
<span style="color: #008000; font-weight: bold">for</span> split <span style="color: #AA22FF; font-weight: bold">in</span> (<span style="color: #666666">0.0458</span>, <span style="color: #666666">0.1298</span>, <span style="color: #666666">0.2873</span>, <span style="color: #666666">0.9040</span>):
|
||||
plt<span style="color: #666666">.</span>plot([split, split], [<span style="color: #666666">-0.2</span>, <span style="color: #666666">1</span>], <span style="color: #BA2121">"k:"</span>, linewidth<span style="color: #666666">=1</span>)
|
||||
plt<span style="color: #666666">.</span>text(<span style="color: #666666">0.3</span>, <span style="color: #666666">0.5</span>, <span style="color: #BA2121">"Depth=2"</span>, fontsize<span style="color: #666666">=13</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"max_depth=3"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
This leads us to a set of different methods that can combine different
|
||||
machine learning algorithms or just use one of them to construct
|
||||
forests and jungles of trees, homogeneous ones or heterogenous
|
||||
ones. These methods are recognized by different names which we will
|
||||
try to explain here. These are
|
||||
|
||||
<ol>
|
||||
<li> Voting classifiers</li>
|
||||
<li> Bagging and Pasting</li>
|
||||
<li> Random forests</li>
|
||||
<li> Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)</li>
|
||||
</ol>
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>tree_reg1 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>)
|
||||
tree_reg2 <span style="color: #666666">=</span> DecisionTreeRegressor(random_state<span style="color: #666666">=42</span>, min_samples_leaf<span style="color: #666666">=10</span>)
|
||||
tree_reg1<span style="color: #666666">.</span>fit(X, y)
|
||||
tree_reg2<span style="color: #666666">.</span>fit(X, y)
|
||||
|
||||
We discuss these methods here.
|
||||
x1 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">500</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
y_pred1 <span style="color: #666666">=</span> tree_reg1<span style="color: #666666">.</span>predict(x1)
|
||||
y_pred2 <span style="color: #666666">=</span> tree_reg2<span style="color: #666666">.</span>predict(x1)
|
||||
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
|
||||
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred1, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1.1</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"$y$"</span>, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"upper center"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"No restrictions"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X, y, <span style="color: #BA2121">"b."</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x1, y_pred2, <span style="color: #BA2121">"r.-"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">r"$\hat</span><span style="color: #BB6688; font-weight: bold">{y}</span><span style="color: #BA2121">$"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">-0.2</span>, <span style="color: #666666">1.1</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"min_samples_leaf=</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">"</span><span style="color: #666666">.</span>format(tree_reg2<span style="color: #666666">.</span>min_samples_leaf), fontsize<span style="color: #666666">=14</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -249,6 +309,9 @@ We discuss these methods here.
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs035.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,12 +210,18 @@ MathJax.Hub.Config({
|
||||
<a name="part0035"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec34" class="anchor">An Overview of Ensemble Methods </h2>
|
||||
<h2 id="___sec34" class="anchor">Pros and cons of trees, pros </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/ensembleoverview.png" align="bottom" width=600></p></center><br /><br />
|
||||
<ul>
|
||||
<li> White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)</li>
|
||||
<li> Trees are very easy to explain to people. In fact, they are even easier to explain than linear regression!</li>
|
||||
<li> No feature normalization needed</li>
|
||||
<li> Tree models can handle both continuous and categorical data (Classification and Regression Trees)</li>
|
||||
<li> Can model nonlinear relationships</li>
|
||||
<li> Can model interactions between the different descriptive features</li>
|
||||
<li> Trees can be displayed graphically, and are easily interpreted even by a non-expert (especially if they are small)</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -229,6 +244,10 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs036.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,21 +210,21 @@ MathJax.Hub.Config({
|
||||
<a name="part0036"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec35" class="anchor">Bagging </h2>
|
||||
<h2 id="___sec35" class="anchor">Disadvantages </h2>
|
||||
|
||||
<p>
|
||||
The <b>plain</b> decision trees suffer from high
|
||||
variance. This means that if we split the training data into two parts
|
||||
at random, and fit a decision tree to both halves, the results that we
|
||||
get could be quite different. In contrast, a procedure with low
|
||||
variance will yield similar results if applied repeatedly to distinct
|
||||
data sets; linear regression tends to have low variance, if the ratio
|
||||
of \( n \) to \( p \) is moderately large.
|
||||
<ul>
|
||||
<li> Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches</li>
|
||||
<li> If continuous features are used the tree may become quite large and hence less interpretable</li>
|
||||
<li> Decision trees are prone to overfit the training data and hence do not well generalize the data if no stopping criteria or improvements like pruning, boosting or bagging are implemented</li>
|
||||
<li> Small changes in the data may lead to a completely different tree. This issue can be addressed by using ensemble methods like bagging, boosting or random forests</li>
|
||||
<li> Unbalanced datasets where some target feature values occur much more frequently than others may lead to biased trees since the frequently occurring feature values are preferred over the less frequently occurring ones.</li>
|
||||
<li> If the number of features is relatively large (high dimensional) and the number of instances is relatively low, the tree might overfit the data</li>
|
||||
<li> Features with many levels may be preferred over features with less levels since for them it is <em>more easy</em> to split the dataset such that the sub datasets only contain pure target feature values. This issue can be addressed by preferring for instance the information gain ratio as splitting criteria over information gain</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<b>Bootstrap aggregation</b>, or just <b>bagging</b>, is a
|
||||
general-purpose procedure for reducing the variance of a statistical
|
||||
learning method.
|
||||
However, by aggregating many decision trees, using methods like
|
||||
bagging, random forests, and boosting, the predictive performance of
|
||||
trees can be substantially improved.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -239,6 +248,9 @@ learning method.
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs037.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,31 +210,29 @@ MathJax.Hub.Config({
|
||||
<a name="part0037"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec36" class="anchor">More bagging </h2>
|
||||
<h2 id="___sec36" class="anchor">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
|
||||
<p>
|
||||
Bagging typically results in improved accuracy
|
||||
over prediction using a single tree. Unfortunately, however, it can be
|
||||
difficult to interpret the resulting model. Recall that one of the
|
||||
advantages of decision trees is the attractive and easily interpreted
|
||||
diagram that results.
|
||||
As stated above and seen in many of the examples discussed here about
|
||||
a single decision tree, we often end up overfitting our training
|
||||
data. This normally means that we have a high variance. Can we reduce
|
||||
the variance of a statistical learning method?
|
||||
|
||||
<p>
|
||||
However, when we bag a large number of trees, it is no longer
|
||||
possible to represent the resulting statistical learning procedure
|
||||
using a single tree, and it is no longer clear which variables are
|
||||
most important to the procedure. Thus, bagging improves prediction
|
||||
accuracy at the expense of interpretability. Although the collection
|
||||
of bagged trees is much more difficult to interpret than a single
|
||||
tree, one can obtain an overall summary of the importance of each
|
||||
predictor using the MSE (for bagging regression trees) or the Gini
|
||||
index (for bagging classification trees). In the case of bagging
|
||||
regression trees, we can record the total amount that the MSE is
|
||||
decreased due to splits over a given predictor, averaged over all \( B \) possible
|
||||
trees. A large value indicates an important predictor. Similarly, in
|
||||
the context of bagging classification trees, we can add up the total
|
||||
amount that the Gini index is decreased by splits over a given
|
||||
predictor, averaged over all \( B \) trees.
|
||||
This leads us to a set of different methods that can combine different
|
||||
machine learning algorithms or just use one of them to construct
|
||||
forests and jungles of trees, homogeneous ones or heterogenous
|
||||
ones. These methods are recognized by different names which we will
|
||||
try to explain here. These are
|
||||
|
||||
<ol>
|
||||
<li> Voting classifiers</li>
|
||||
<li> Bagging and Pasting</li>
|
||||
<li> Random forests</li>
|
||||
<li> Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)</li>
|
||||
</ol>
|
||||
|
||||
We discuss these methods here.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -248,6 +255,9 @@ predictor, averaged over all \( B \) trees.
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs038.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,24 +210,11 @@ MathJax.Hub.Config({
|
||||
<a name="part0038"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec37" class="anchor">Simple Voting Example, head or tail </h2>
|
||||
<p>
|
||||
<h2 id="___sec37" class="anchor">An Overview of Ensemble Methods </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/ensembleoverview.png" align="bottom" width=600></p></center><br /><br />
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>heads_proba <span style="color: #666666">=</span> <span style="color: #666666">0.51</span>
|
||||
coin_tosses <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">10000</span>, <span style="color: #666666">10</span>) <span style="color: #666666"><</span> heads_proba)<span style="color: #666666">.</span>astype(np<span style="color: #666666">.</span>int32)
|
||||
cumulative_heads_ratio <span style="color: #666666">=</span> np<span style="color: #666666">.</span>cumsum(coin_tosses, axis<span style="color: #666666">=0</span>) <span style="color: #666666">/</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">1</span>, <span style="color: #666666">10001</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">8</span>,<span style="color: #666666">3.5</span>))
|
||||
plt<span style="color: #666666">.</span>plot(cumulative_heads_ratio)
|
||||
plt<span style="color: #666666">.</span>plot([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>], [<span style="color: #666666">0.51</span>, <span style="color: #666666">0.51</span>], <span style="color: #BA2121">"k--"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"51%"</span>)
|
||||
plt<span style="color: #666666">.</span>plot([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>], [<span style="color: #666666">0.5</span>, <span style="color: #666666">0.5</span>], <span style="color: #BA2121">"k-"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"50%"</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Number of coin tosses"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Heads ratio"</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"lower right"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>, <span style="color: #666666">0.42</span>, <span style="color: #666666">0.58</span>])
|
||||
save_fig(<span style="color: #BA2121">"votingsimple"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -239,6 +235,9 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs039.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,54 +210,22 @@ MathJax.Hub.Config({
|
||||
<a name="part0039"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec38" class="anchor">Using the Voting Classifier </h2>
|
||||
<h2 id="___sec38" class="anchor">Bagging </h2>
|
||||
|
||||
<p>
|
||||
The <b>plain</b> decision trees suffer from high
|
||||
variance. This means that if we split the training data into two parts
|
||||
at random, and fit a decision tree to both halves, the results that we
|
||||
get could be quite different. In contrast, a procedure with low
|
||||
variance will yield similar results if applied repeatedly to distinct
|
||||
data sets; linear regression tends to have low variance, if the ratio
|
||||
of \( n \) to \( p \) is moderately large.
|
||||
|
||||
<!-- 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.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> make_moons
|
||||
<p>
|
||||
<b>Bootstrap aggregation</b>, or just <b>bagging</b>, is a
|
||||
general-purpose procedure for reducing the variance of a statistical
|
||||
learning method.
|
||||
|
||||
X, y <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=500</span>, noise<span style="color: #666666">=0.30</span>, random_state<span style="color: #666666">=42</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, random_state<span style="color: #666666">=42</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> RandomForestClassifier
|
||||
<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> VotingClassifier
|
||||
<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.svm</span> <span style="color: #008000; font-weight: bold">import</span> SVC
|
||||
|
||||
log_clf <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">"liblinear"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=10</span>, random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">"auto"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'hard'</span>)
|
||||
|
||||
voting_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.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
|
||||
log_clf <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">"liblinear"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=10</span>, random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">"auto"</span>, probability<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'soft'</span>)
|
||||
voting_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.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -268,6 +245,9 @@ voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs040.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,62 +210,32 @@ MathJax.Hub.Config({
|
||||
<a name="part0040"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec39" class="anchor">Please, not the moons again! Voting and Bagging </h2>
|
||||
<h2 id="___sec39" class="anchor">More bagging </h2>
|
||||
|
||||
<p>
|
||||
Bagging typically results in improved accuracy
|
||||
over prediction using a single tree. Unfortunately, however, it can be
|
||||
difficult to interpret the resulting model. Recall that one of the
|
||||
advantages of decision trees is the attractive and easily interpreted
|
||||
diagram that results.
|
||||
|
||||
<!-- 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.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> make_moons
|
||||
|
||||
X, y <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=500</span>, noise<span style="color: #666666">=0.30</span>, random_state<span style="color: #666666">=42</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, random_state<span style="color: #666666">=42</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> RandomForestClassifier
|
||||
<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> VotingClassifier
|
||||
<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.svm</span> <span style="color: #008000; font-weight: bold">import</span> SVC
|
||||
|
||||
log_clf <span style="color: #666666">=</span> LogisticRegression(random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'hard'</span>)
|
||||
voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
</pre></div>
|
||||
<p>
|
||||
However, when we bag a large number of trees, it is no longer
|
||||
possible to represent the resulting statistical learning procedure
|
||||
using a single tree, and it is no longer clear which variables are
|
||||
most important to the procedure. Thus, bagging improves prediction
|
||||
accuracy at the expense of interpretability. Although the collection
|
||||
of bagged trees is much more difficult to interpret than a single
|
||||
tree, one can obtain an overall summary of the importance of each
|
||||
predictor using the MSE (for bagging regression trees) or the Gini
|
||||
index (for bagging classification trees). In the case of bagging
|
||||
regression trees, we can record the total amount that the MSE is
|
||||
decreased due to splits over a given predictor, averaged over all \( B \) possible
|
||||
trees. A large value indicates an important predictor. Similarly, in
|
||||
the context of bagging classification trees, we can add up the total
|
||||
amount that the Gini index is decreased by splits over a given
|
||||
predictor, averaged over all \( B \) 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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>log_clf <span style="color: #666666">=</span> LogisticRegression(random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(probability<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'soft'</span>)
|
||||
voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
</pre></div>
|
||||
<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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -275,6 +254,9 @@ voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<li class="active"><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs041.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,63 +210,22 @@ MathJax.Hub.Config({
|
||||
<a name="part0041"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec40" class="anchor">Bagging Examples </h2>
|
||||
|
||||
<h2 id="___sec40" class="anchor">Simple Voting Example, head or tail </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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> BaggingClassifier
|
||||
<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
|
||||
|
||||
bag_clf <span style="color: #666666">=</span> BaggingClassifier(
|
||||
DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>), n_estimators<span style="color: #666666">=500</span>,
|
||||
max_samples<span style="color: #666666">=100</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>)
|
||||
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)
|
||||
</pre></div>
|
||||
<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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
<span style="color: #008000">print</span>(accuracy_score(y_test, y_pred))
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(random_state<span style="color: #666666">=42</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred_tree <span style="color: #666666">=</span> tree_clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(accuracy_score(y_test, y_pred_tree))
|
||||
</pre></div>
|
||||
<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">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib.colors</span> <span style="color: #008000; font-weight: bold">import</span> ListedColormap
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot_decision_boundary</span>(clf, X, y, axes<span style="color: #666666">=</span>[<span style="color: #666666">-1.5</span>, <span style="color: #666666">2.5</span>, <span style="color: #666666">-1</span>, <span style="color: #666666">1.5</span>], alpha<span style="color: #666666">=0.5</span>, contour<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>):
|
||||
x1s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">0</span>], axes[<span style="color: #666666">1</span>], <span style="color: #666666">100</span>)
|
||||
x2s <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(axes[<span style="color: #666666">2</span>], axes[<span style="color: #666666">3</span>], <span style="color: #666666">100</span>)
|
||||
x1, x2 <span style="color: #666666">=</span> np<span style="color: #666666">.</span>meshgrid(x1s, x2s)
|
||||
X_new <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[x1<span style="color: #666666">.</span>ravel(), x2<span style="color: #666666">.</span>ravel()]
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_new)<span style="color: #666666">.</span>reshape(x1<span style="color: #666666">.</span>shape)
|
||||
custom_cmap <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#fafab0'</span>,<span style="color: #BA2121">'#9898ff'</span>,<span style="color: #BA2121">'#a0faa0'</span>])
|
||||
plt<span style="color: #666666">.</span>contourf(x1, x2, y_pred, alpha<span style="color: #666666">=0.3</span>, cmap<span style="color: #666666">=</span>custom_cmap)
|
||||
<span style="color: #008000; font-weight: bold">if</span> contour:
|
||||
custom_cmap2 <span style="color: #666666">=</span> ListedColormap([<span style="color: #BA2121">'#7d7d58'</span>,<span style="color: #BA2121">'#4c4c7f'</span>,<span style="color: #BA2121">'#507d50'</span>])
|
||||
plt<span style="color: #666666">.</span>contour(x1, x2, y_pred, cmap<span style="color: #666666">=</span>custom_cmap2, alpha<span style="color: #666666">=0.8</span>)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==0</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==0</span>], <span style="color: #BA2121">"yo"</span>, alpha<span style="color: #666666">=</span>alpha)
|
||||
plt<span style="color: #666666">.</span>plot(X[:, <span style="color: #666666">0</span>][y<span style="color: #666666">==1</span>], X[:, <span style="color: #666666">1</span>][y<span style="color: #666666">==1</span>], <span style="color: #BA2121">"bs"</span>, alpha<span style="color: #666666">=</span>alpha)
|
||||
plt<span style="color: #666666">.</span>axis(axes)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r"$x_1$"</span>, fontsize<span style="color: #666666">=18</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r"$x_2$"</span>, fontsize<span style="color: #666666">=18</span>, rotation<span style="color: #666666">=0</span>)
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>,<span style="color: #666666">4</span>))
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">121</span>)
|
||||
plot_decision_boundary(tree_clf, X, y)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Decision Tree"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
plt<span style="color: #666666">.</span>subplot(<span style="color: #666666">122</span>)
|
||||
plot_decision_boundary(bag_clf, X, y)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Decision Trees with Bagging"</span>, fontsize<span style="color: #666666">=14</span>)
|
||||
save_fig(<span style="color: #BA2121">"baggingtree"</span>)
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>heads_proba <span style="color: #666666">=</span> <span style="color: #666666">0.51</span>
|
||||
coin_tosses <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">10000</span>, <span style="color: #666666">10</span>) <span style="color: #666666"><</span> heads_proba)<span style="color: #666666">.</span>astype(np<span style="color: #666666">.</span>int32)
|
||||
cumulative_heads_ratio <span style="color: #666666">=</span> np<span style="color: #666666">.</span>cumsum(coin_tosses, axis<span style="color: #666666">=0</span>) <span style="color: #666666">/</span> np<span style="color: #666666">.</span>arange(<span style="color: #666666">1</span>, <span style="color: #666666">10001</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">8</span>,<span style="color: #666666">3.5</span>))
|
||||
plt<span style="color: #666666">.</span>plot(cumulative_heads_ratio)
|
||||
plt<span style="color: #666666">.</span>plot([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>], [<span style="color: #666666">0.51</span>, <span style="color: #666666">0.51</span>], <span style="color: #BA2121">"k--"</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"51%"</span>)
|
||||
plt<span style="color: #666666">.</span>plot([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>], [<span style="color: #666666">0.5</span>, <span style="color: #666666">0.5</span>], <span style="color: #BA2121">"k-"</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">"50%"</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">"Number of coin tosses"</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">"Heads ratio"</span>)
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">"lower right"</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">10000</span>, <span style="color: #666666">0.42</span>, <span style="color: #666666">0.58</span>])
|
||||
save_fig(<span style="color: #BA2121">"votingsimple"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -277,6 +245,9 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li class="active"><a href="._week44-bs041.html">42</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs042.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -201,74 +210,55 @@ MathJax.Hub.Config({
|
||||
<a name="part0042"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec41" class="anchor">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
|
||||
<p>
|
||||
Let us bring up our good old boostrap example from the linear regression lectures. We change the linerar regression algorithm with
|
||||
a decision tree wth different depths and perform a bootstrap aggregate (in this case we perform as many bootstraps as data points \( n \)).
|
||||
<h2 id="___sec41" class="anchor">Using the Voting Classifier </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">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.pipeline</span> <span style="color: #008000; font-weight: bold">import</span> make_pipeline
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.utils</span> <span style="color: #008000; font-weight: bold">import</span> resample
|
||||
<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> DecisionTreeRegressor
|
||||
<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.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> make_moons
|
||||
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
n_boostraps <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
maxdepth <span style="color: #666666">=</span> <span style="color: #666666">8</span>
|
||||
X, y <span style="color: #666666">=</span> make_moons(n_samples<span style="color: #666666">=500</span>, noise<span style="color: #666666">=0.30</span>, random_state<span style="color: #666666">=42</span>)
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, random_state<span style="color: #666666">=42</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(maxdepth)
|
||||
bias <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdepth)
|
||||
variance <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdepth)
|
||||
polydegree <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(maxdepth)
|
||||
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>)
|
||||
<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.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> VotingClassifier
|
||||
<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.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.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)
|
||||
log_clf <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">"liblinear"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=10</span>, random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">"auto"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># we produce a simple tree first as benchmark</span>
|
||||
simpletree <span style="color: #666666">=</span> DecisionTreeRegressor(max_depth<span style="color: #666666">=3</span>)
|
||||
simpletree<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
simpleprediction <span style="color: #666666">=</span> simpletree<span style="color: #666666">.</span>predict(X_test_scaled)
|
||||
<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>,maxdepth):
|
||||
model <span style="color: #666666">=</span> DecisionTreeRegressor(max_depth<span style="color: #666666">=</span>degree)
|
||||
y_pred <span style="color: #666666">=</span> np<span style="color: #666666">.</span>empty((y_test<span style="color: #666666">.</span>shape[<span style="color: #666666">0</span>], n_boostraps))
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(n_boostraps):
|
||||
x_, y_ <span style="color: #666666">=</span> resample(X_train_scaled, y_train)
|
||||
model<span style="color: #666666">.</span>fit(x_, y_)
|
||||
y_pred[:, i] <span style="color: #666666">=</span> model<span style="color: #666666">.</span>predict(X_test_scaled)<span style="color: #408080; font-style: italic">#.ravel()</span>
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'hard'</span>)
|
||||
|
||||
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>, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</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, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>))<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, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>) )
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Polynomial degree:'</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]))
|
||||
voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
|
||||
mse_simpletree <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> simpleprediction)<span style="color: #666666">**2</span>)
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdepth)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'MSE simple tree'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, mse_simpletree, label<span style="color: #666666">=</span><span style="color: #BA2121">'MSE for Bootstrap'</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">"baggingboot"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
<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> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
|
||||
log_clf <span style="color: #666666">=</span> LogisticRegression(solver<span style="color: #666666">=</span><span style="color: #BA2121">"liblinear"</span>, random_state<span style="color: #666666">=42</span>)
|
||||
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=10</span>, random_state<span style="color: #666666">=42</span>)
|
||||
svm_clf <span style="color: #666666">=</span> SVC(gamma<span style="color: #666666">=</span><span style="color: #BA2121">"auto"</span>, probability<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>, random_state<span style="color: #666666">=42</span>)
|
||||
|
||||
voting_clf <span style="color: #666666">=</span> VotingClassifier(
|
||||
estimators<span style="color: #666666">=</span>[(<span style="color: #BA2121">'lr'</span>, log_clf), (<span style="color: #BA2121">'rf'</span>, rnd_clf), (<span style="color: #BA2121">'svc'</span>, svm_clf)],
|
||||
voting<span style="color: #666666">=</span><span style="color: #BA2121">'soft'</span>)
|
||||
voting_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.metrics</span> <span style="color: #008000; font-weight: bold">import</span> accuracy_score
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> clf <span style="color: #AA22FF; font-weight: bold">in</span> (log_clf, rnd_clf, svm_clf, voting_clf):
|
||||
clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
y_pred <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X_test)
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span><span style="color: #19177C">__class__</span><span style="color: #666666">.</span><span style="color: #19177C">__name__</span>, accuracy_score(y_test, y_pred))
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -284,6 +274,10 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week44-bs040.html">41</a></li>
|
||||
<li><a href="._week44-bs041.html">42</a></li>
|
||||
<li class="active"><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs043.html">44</a></li>
|
||||
<li><a href="._week44-bs044.html">45</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-bs043.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -44,69 +44,75 @@ Automatically generated HTML file from DocOnce source
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -147,45 +153,48 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs001.html#___sec0" style="font-size: 80%;">Overview of week 44</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs002.html#___sec1" style="font-size: 80%;">Thursday</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs003.html#___sec2" style="font-size: 80%;">Decision trees, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs004.html#___sec3" style="font-size: 80%;">Basics of a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs005.html#___sec4" style="font-size: 80%;">A Sketch of a Tree, Regression problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs006.html#___sec5" style="font-size: 80%;">A Sketch of a Tree, Classification problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs007.html#___sec6" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs008.html#___sec7" style="font-size: 80%;">General Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs009.html#___sec8" style="font-size: 80%;">How do we set it up?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs010.html#___sec9" style="font-size: 80%;">Decision trees and Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs011.html#___sec10" style="font-size: 80%;">Building a tree, regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs012.html#___sec11" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs013.html#___sec12" style="font-size: 80%;">Making a tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs014.html#___sec13" style="font-size: 80%;">Pruning the tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs015.html#___sec14" style="font-size: 80%;">Cost complexity pruning</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs016.html#___sec15" style="font-size: 80%;">Schematic Regression Procedure</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs017.html#___sec16" style="font-size: 80%;">A Classification Tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs018.html#___sec17" style="font-size: 80%;">Growing a classification tree</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs019.html#___sec18" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs020.html#___sec19" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs021.html#___sec20" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs022.html#___sec21" style="font-size: 80%;">Algorithms for Setting up Decision Trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs023.html#___sec22" style="font-size: 80%;">The CART algorithm for Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs024.html#___sec23" style="font-size: 80%;">The CART algorithm for Regression</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs025.html#___sec24" style="font-size: 80%;">Computing the Gini index</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs026.html#___sec25" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs027.html#___sec26" style="font-size: 80%;">Computing the Gini Factor</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs028.html#___sec27" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs029.html#___sec28" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs030.html#___sec29" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs031.html#___sec30" style="font-size: 80%;">Another example, the moons again</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs032.html#___sec31" style="font-size: 80%;">Playing around with regions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs033.html#___sec32" style="font-size: 80%;">Regression trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs034.html#___sec33" style="font-size: 80%;">Final regressor code</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs035.html#___sec34" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs036.html#___sec35" style="font-size: 80%;">Disadvantages</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs037.html#___sec36" style="font-size: 80%;">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs038.html#___sec37" style="font-size: 80%;">An Overview of Ensemble Methods</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs039.html#___sec38" style="font-size: 80%;">Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs040.html#___sec39" style="font-size: 80%;">More bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs041.html#___sec40" style="font-size: 80%;">Simple Voting Example, head or tail</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs042.html#___sec41" style="font-size: 80%;">Using the Voting Classifier</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs043.html#___sec42" style="font-size: 80%;">Please, not the moons again! Voting and Bagging</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs044.html#___sec43" style="font-size: 80%;">Bagging Examples</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week44-bs045.html#___sec44" style="font-size: 80%;">Making your own Bootstrap: Changing the Level of the Decision Tree</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -220,7 +229,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>Oct 26, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 27, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -244,7 +253,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week44-bs008.html">9</a></li>
|
||||
<li><a href="._week44-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week44-bs042.html">43</a></li>
|
||||
<li><a href="._week44-bs045.html">46</a></li>
|
||||
<li><a href="._week44-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>Oct 26, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 27, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -206,6 +206,11 @@ The descriptive features which reproduce best the target/output features are nor
|
||||
to be the most informative ones. The process of finding the <b>most
|
||||
informative</b> feature is done until we accomplish a stopping criteria
|
||||
where we then finally end up in so called <b>leaf nodes</b>.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec3">Basics of a tree </h2>
|
||||
|
||||
<p>
|
||||
A decision tree is typically divided into a <b>root node</b>, the <b>interior nodes</b>,
|
||||
@@ -222,7 +227,23 @@ given some assumptions, make predictions about the target feature value
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec3">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
<h2 id="___sec4">A Sketch of a Tree, Regression problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8] -->
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec5">A Sketch of a Tree, Classification problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8] -->
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec6">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/cancer.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -233,7 +254,7 @@ This tree was produced using the Wisconsin cancer data (discussed here as well,
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec4">General Features </h2>
|
||||
<h2 id="___sec7">General Features </h2>
|
||||
|
||||
<p>
|
||||
The overarching approach to decision trees is a top-down approach.
|
||||
@@ -252,7 +273,7 @@ node.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec5">How do we set it up? </h2>
|
||||
<h2 id="___sec8">How do we set it up? </h2>
|
||||
|
||||
<p>
|
||||
In simplified terms, the process of training a decision tree and
|
||||
@@ -271,7 +292,7 @@ Then we are essentially done!
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec6">Decision trees and Regression </h2>
|
||||
<h2 id="___sec9">Decision trees and Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -368,7 +389,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec7">Building a tree, regression </h2>
|
||||
<h2 id="___sec10">Building a tree, regression </h2>
|
||||
|
||||
<p>
|
||||
There are mainly two steps
|
||||
@@ -400,7 +421,7 @@ within box \( j \).
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec8">A top-down approach, recursive binary splitting </h2>
|
||||
<h2 id="___sec11">A top-down approach, recursive binary splitting </h2>
|
||||
|
||||
<p>
|
||||
Unfortunately, it is computationally infeasible to consider every
|
||||
@@ -419,7 +440,7 @@ better tree in some future step.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec9">Making a tree </h2>
|
||||
<h2 id="___sec12">Making a tree </h2>
|
||||
|
||||
<p>
|
||||
In order to implement the recursive binary splitting we start by selecting
|
||||
@@ -476,7 +497,7 @@ region contains more than five observations.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec10">Pruning the tree </h2>
|
||||
<h2 id="___sec13">Pruning the tree </h2>
|
||||
|
||||
<p>
|
||||
The above procedure is rather straightforward, but leads often to
|
||||
@@ -495,7 +516,7 @@ parameter \( \alpha \).
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec11">Cost complexity pruning </h2>
|
||||
<h2 id="___sec14">Cost complexity pruning </h2>
|
||||
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
|
||||
<p> <br>
|
||||
$$
|
||||
@@ -528,7 +549,7 @@ subtree corresponding to \( \alpha \).
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec12">Schematic Regression Procedure </h2>
|
||||
<h2 id="___sec15">Schematic Regression Procedure </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -553,7 +574,7 @@ subtree corresponding to \( \alpha \).
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec13">A Classification Tree </h2>
|
||||
<h2 id="___sec16">A Classification Tree </h2>
|
||||
|
||||
<p>
|
||||
A classification tree is very similar to a regression tree, except
|
||||
@@ -572,7 +593,7 @@ fall into that region.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec14">Growing a classification tree </h2>
|
||||
<h2 id="___sec17">Growing a classification tree </h2>
|
||||
|
||||
<p>
|
||||
The task of growing a
|
||||
@@ -596,7 +617,7 @@ than is the classification error rate.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec15">Classification tree, how to split nodes </h2>
|
||||
<h2 id="___sec18">Classification tree, how to split nodes </h2>
|
||||
|
||||
<p>
|
||||
If our targets are the outcome of a classification process that takes
|
||||
@@ -651,7 +672,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec16">Visualizing the Tree, Classification </h2>
|
||||
<h2 id="___sec19">Visualizing the Tree, Classification </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -693,7 +714,7 @@ os.system(cmd)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec17">Visualizing the Tree, The Moons </h2>
|
||||
<h2 id="___sec20">Visualizing the Tree, The Moons </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -726,7 +747,7 @@ os.system(cmd)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec18">Algorithms for Setting up Decision Trees </h2>
|
||||
<h2 id="___sec21">Algorithms for Setting up Decision Trees </h2>
|
||||
|
||||
<p>
|
||||
Two algorithms stand out in the set up of decision trees:
|
||||
@@ -745,7 +766,7 @@ in two branches.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec19">The CART algorithm for Classification </h2>
|
||||
<h2 id="___sec22">The CART algorithm for Classification </h2>
|
||||
|
||||
<p>
|
||||
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
|
||||
@@ -774,7 +795,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec20">The CART algorithm for Regression </h2>
|
||||
<h2 id="___sec23">The CART algorithm for Regression </h2>
|
||||
|
||||
<p>
|
||||
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
|
||||
@@ -808,7 +829,7 @@ just like for classification tasks, is prone to overfitting.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec21">Computing the Gini index </h2>
|
||||
<h2 id="___sec24">Computing the Gini index </h2>
|
||||
|
||||
<p>
|
||||
The example we will look at is a classical one in many Machine
|
||||
@@ -849,7 +870,7 @@ The table here summarizes the various attributes and
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec22">Simple Python Code to read in Data and perform Classification </h2>
|
||||
<h2 id="___sec25">Simple Python Code to read in Data and perform Classification </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -926,7 +947,7 @@ os.system(cmd)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec23">Computing the Gini Factor </h2>
|
||||
<h2 id="___sec26">Computing the Gini Factor </h2>
|
||||
|
||||
<p>
|
||||
The above functions (gini, entropy and misclassification error) are
|
||||
@@ -1005,7 +1026,7 @@ split = get_split(dataset)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec24">Entropy and the ID3 algorithm </h2>
|
||||
<h2 id="___sec27">Entropy and the ID3 algorithm </h2>
|
||||
|
||||
<p>
|
||||
ID3, learns decision trees by constructing
|
||||
@@ -1042,7 +1063,7 @@ attributes at each step while growing the tree.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec25">Implementing the ID3 Algorithm </h2>
|
||||
<h2 id="___sec28">Implementing the ID3 Algorithm </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1239,7 +1260,7 @@ attributes at each step while growing the tree.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec26">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<h2 id="___sec29">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1289,7 +1310,7 @@ deep_tree_clf.fit(X_train_scaled, y_train)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec27">Another example, the moons again </h2>
|
||||
<h2 id="___sec30">Another example, the moons again </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1362,7 +1383,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec28">Playing around with regions </h2>
|
||||
<h2 id="___sec31">Playing around with regions </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1391,7 +1412,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec29">Regression trees </h2>
|
||||
<h2 id="___sec32">Regression trees </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1414,7 +1435,7 @@ tree_reg.fit(X, y)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec30">Final regressor code </h2>
|
||||
<h2 id="___sec33">Final regressor code </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1493,7 +1514,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec31">Pros and cons of trees, pros </h2>
|
||||
<h2 id="___sec34">Pros and cons of trees, pros </h2>
|
||||
|
||||
<ul>
|
||||
<p><li> White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)</li>
|
||||
@@ -1508,7 +1529,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec32">Disadvantages </h2>
|
||||
<h2 id="___sec35">Disadvantages </h2>
|
||||
|
||||
<ul>
|
||||
<p><li> Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches</li>
|
||||
@@ -1528,7 +1549,7 @@ trees can be substantially improved.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec33">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
<h2 id="___sec36">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
|
||||
<p>
|
||||
As stated above and seen in many of the examples discussed here about
|
||||
@@ -1556,7 +1577,7 @@ We discuss these methods here.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec34">An Overview of Ensemble Methods </h2>
|
||||
<h2 id="___sec37">An Overview of Ensemble Methods </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/ensembleoverview.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -1564,7 +1585,7 @@ We discuss these methods here.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec35">Bagging </h2>
|
||||
<h2 id="___sec38">Bagging </h2>
|
||||
|
||||
<p>
|
||||
The <b>plain</b> decision trees suffer from high
|
||||
@@ -1583,7 +1604,7 @@ learning method.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec36">More bagging </h2>
|
||||
<h2 id="___sec39">More bagging </h2>
|
||||
|
||||
<p>
|
||||
Bagging typically results in improved accuracy
|
||||
@@ -1612,7 +1633,7 @@ predictor, averaged over all \( B \) trees.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec37">Simple Voting Example, head or tail </h2>
|
||||
<h2 id="___sec40">Simple Voting Example, head or tail </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1634,7 +1655,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec38">Using the Voting Classifier </h2>
|
||||
<h2 id="___sec41">Using the Voting Classifier </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1686,7 +1707,7 @@ voting_clf.fit(X_train, y_train)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec39">Please, not the moons again! Voting and Bagging </h2>
|
||||
<h2 id="___sec42">Please, not the moons again! Voting and Bagging </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1746,7 +1767,7 @@ voting_clf.fit(X_train, y_train)
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec40">Bagging Examples </h2>
|
||||
<h2 id="___sec43">Bagging Examples </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1809,7 +1830,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec41">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
<h2 id="___sec44">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
|
||||
<p>
|
||||
Let us bring up our good old boostrap example from the linear regression lectures. We change the linerar regression algorithm with
|
||||
|
||||
@@ -64,69 +64,75 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -168,7 +174,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>Oct 26, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 27, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -220,6 +226,11 @@ to be the most informative ones. The process of finding the <b>most
|
||||
informative</b> feature is done until we accomplish a stopping criteria
|
||||
where we then finally end up in so called <b>leaf nodes</b>.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">Basics of a tree </h2>
|
||||
|
||||
<p>
|
||||
A decision tree is typically divided into a <b>root node</b>, the <b>interior nodes</b>,
|
||||
and the final <b>leaf nodes</b> or just <b>leaves</b>. These entities are then connected by so-called <b>branches</b>.
|
||||
@@ -235,7 +246,23 @@ given some assumptions, make predictions about the target feature value
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
<h2 id="___sec4">A Sketch of a Tree, Regression problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">A Sketch of a Tree, Classification problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/cancer.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -246,7 +273,7 @@ This tree was produced using the Wisconsin cancer data (discussed here as well,
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec4">General Features </h2>
|
||||
<h2 id="___sec7">General Features </h2>
|
||||
|
||||
<p>
|
||||
The overarching approach to decision trees is a top-down approach.
|
||||
@@ -264,7 +291,7 @@ node.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">How do we set it up? </h2>
|
||||
<h2 id="___sec8">How do we set it up? </h2>
|
||||
|
||||
<p>
|
||||
In simplified terms, the process of training a decision tree and
|
||||
@@ -282,7 +309,7 @@ Then we are essentially done!
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">Decision trees and Regression </h2>
|
||||
<h2 id="___sec9">Decision trees and Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -378,7 +405,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec7">Building a tree, regression </h2>
|
||||
<h2 id="___sec10">Building a tree, regression </h2>
|
||||
|
||||
<p>
|
||||
There are mainly two steps
|
||||
@@ -406,7 +433,7 @@ within box \( j \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec8">A top-down approach, recursive binary splitting </h2>
|
||||
<h2 id="___sec11">A top-down approach, recursive binary splitting </h2>
|
||||
|
||||
<p>
|
||||
Unfortunately, it is computationally infeasible to consider every
|
||||
@@ -425,7 +452,7 @@ better tree in some future step.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec9">Making a tree </h2>
|
||||
<h2 id="___sec12">Making a tree </h2>
|
||||
|
||||
<p>
|
||||
In order to implement the recursive binary splitting we start by selecting
|
||||
@@ -476,7 +503,7 @@ region contains more than five observations.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec10">Pruning the tree </h2>
|
||||
<h2 id="___sec13">Pruning the tree </h2>
|
||||
|
||||
<p>
|
||||
The above procedure is rather straightforward, but leads often to
|
||||
@@ -495,7 +522,7 @@ parameter \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">Cost complexity pruning </h2>
|
||||
<h2 id="___sec14">Cost complexity pruning </h2>
|
||||
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
|
||||
$$
|
||||
\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
|
||||
@@ -526,7 +553,7 @@ subtree corresponding to \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Schematic Regression Procedure </h2>
|
||||
<h2 id="___sec15">Schematic Regression Procedure </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -552,7 +579,7 @@ subtree corresponding to \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">A Classification Tree </h2>
|
||||
<h2 id="___sec16">A Classification Tree </h2>
|
||||
|
||||
<p>
|
||||
A classification tree is very similar to a regression tree, except
|
||||
@@ -571,7 +598,7 @@ fall into that region.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">Growing a classification tree </h2>
|
||||
<h2 id="___sec17">Growing a classification tree </h2>
|
||||
|
||||
<p>
|
||||
The task of growing a
|
||||
@@ -595,7 +622,7 @@ than is the classification error rate.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">Classification tree, how to split nodes </h2>
|
||||
<h2 id="___sec18">Classification tree, how to split nodes </h2>
|
||||
|
||||
<p>
|
||||
If our targets are the outcome of a classification process that takes
|
||||
@@ -645,7 +672,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">Visualizing the Tree, Classification </h2>
|
||||
<h2 id="___sec19">Visualizing the Tree, Classification </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -686,7 +713,7 @@ os.system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">Visualizing the Tree, The Moons </h2>
|
||||
<h2 id="___sec20">Visualizing the Tree, The Moons </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -718,7 +745,7 @@ os.system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec18">Algorithms for Setting up Decision Trees </h2>
|
||||
<h2 id="___sec21">Algorithms for Setting up Decision Trees </h2>
|
||||
|
||||
<p>
|
||||
Two algorithms stand out in the set up of decision trees:
|
||||
@@ -736,7 +763,7 @@ in two branches.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec19">The CART algorithm for Classification </h2>
|
||||
<h2 id="___sec22">The CART algorithm for Classification </h2>
|
||||
|
||||
<p>
|
||||
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
|
||||
@@ -763,7 +790,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec20">The CART algorithm for Regression </h2>
|
||||
<h2 id="___sec23">The CART algorithm for Regression </h2>
|
||||
|
||||
<p>
|
||||
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
|
||||
@@ -791,7 +818,7 @@ just like for classification tasks, is prone to overfitting.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Computing the Gini index </h2>
|
||||
<h2 id="___sec24">Computing the Gini index </h2>
|
||||
|
||||
<p>
|
||||
The example we will look at is a classical one in many Machine
|
||||
@@ -831,7 +858,7 @@ The table here summarizes the various attributes and
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">Simple Python Code to read in Data and perform Classification </h2>
|
||||
<h2 id="___sec25">Simple Python Code to read in Data and perform Classification </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -907,7 +934,7 @@ os.system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec23">Computing the Gini Factor </h2>
|
||||
<h2 id="___sec26">Computing the Gini Factor </h2>
|
||||
|
||||
<p>
|
||||
The above functions (gini, entropy and misclassification error) are
|
||||
@@ -985,7 +1012,7 @@ split = get_split(dataset)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec24">Entropy and the ID3 algorithm </h2>
|
||||
<h2 id="___sec27">Entropy and the ID3 algorithm </h2>
|
||||
|
||||
<p>
|
||||
ID3, learns decision trees by constructing
|
||||
@@ -1021,7 +1048,7 @@ attributes at each step while growing the tree.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec25">Implementing the ID3 Algorithm </h2>
|
||||
<h2 id="___sec28">Implementing the ID3 Algorithm </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1217,7 +1244,7 @@ attributes at each step while growing the tree.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec26">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<h2 id="___sec29">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1266,7 +1293,7 @@ deep_tree_clf.fit(X_train_scaled, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec27">Another example, the moons again </h2>
|
||||
<h2 id="___sec30">Another example, the moons again </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1338,7 +1365,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec28">Playing around with regions </h2>
|
||||
<h2 id="___sec31">Playing around with regions </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1366,7 +1393,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec29">Regression trees </h2>
|
||||
<h2 id="___sec32">Regression trees </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1388,7 +1415,7 @@ tree_reg.fit(X, y)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec30">Final regressor code </h2>
|
||||
<h2 id="___sec33">Final regressor code </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1466,7 +1493,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec31">Pros and cons of trees, pros </h2>
|
||||
<h2 id="___sec34">Pros and cons of trees, pros </h2>
|
||||
|
||||
<ul>
|
||||
<li> White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)</li>
|
||||
@@ -1480,7 +1507,7 @@ plt.show()
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec32">Disadvantages </h2>
|
||||
<h2 id="___sec35">Disadvantages </h2>
|
||||
|
||||
<ul>
|
||||
<li> Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches</li>
|
||||
@@ -1499,7 +1526,7 @@ trees can be substantially improved.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec33">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
<h2 id="___sec36">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
|
||||
<p>
|
||||
As stated above and seen in many of the examples discussed here about
|
||||
@@ -1526,7 +1553,7 @@ We discuss these methods here.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec34">An Overview of Ensemble Methods </h2>
|
||||
<h2 id="___sec37">An Overview of Ensemble Methods </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/ensembleoverview.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -1534,7 +1561,7 @@ We discuss these methods here.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec35">Bagging </h2>
|
||||
<h2 id="___sec38">Bagging </h2>
|
||||
|
||||
<p>
|
||||
The <b>plain</b> decision trees suffer from high
|
||||
@@ -1553,7 +1580,7 @@ learning method.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">More bagging </h2>
|
||||
<h2 id="___sec39">More bagging </h2>
|
||||
|
||||
<p>
|
||||
Bagging typically results in improved accuracy
|
||||
@@ -1582,7 +1609,7 @@ predictor, averaged over all \( B \) trees.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Simple Voting Example, head or tail </h2>
|
||||
<h2 id="___sec40">Simple Voting Example, head or tail </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1603,7 +1630,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">Using the Voting Classifier </h2>
|
||||
<h2 id="___sec41">Using the Voting Classifier </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -1654,7 +1681,7 @@ voting_clf.fit(X_train, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">Please, not the moons again! Voting and Bagging </h2>
|
||||
<h2 id="___sec42">Please, not the moons again! Voting and Bagging </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1713,7 +1740,7 @@ voting_clf.fit(X_train, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec40">Bagging Examples </h2>
|
||||
<h2 id="___sec43">Bagging Examples </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1775,7 +1802,7 @@ plt.show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
<h2 id="___sec44">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
|
||||
<p>
|
||||
Let us bring up our good old boostrap example from the linear regression lectures. We change the linerar regression algorithm with
|
||||
|
||||
+106
-79
@@ -69,69 +69,75 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
'sections': [('Overview of week 44', 2, None, '___sec0'),
|
||||
('Thursday', 2, None, '___sec1'),
|
||||
('Decision trees, overarching aims', 2, None, '___sec2'),
|
||||
('Basics of a tree', 2, None, '___sec3'),
|
||||
('A Sketch of a Tree, Regression problem', 2, None, '___sec4'),
|
||||
('A Sketch of a Tree, Classification problem',
|
||||
2,
|
||||
None,
|
||||
'___sec5'),
|
||||
('A typical Decision Tree with its pertinent Jargon, '
|
||||
'Classification Problem',
|
||||
2,
|
||||
None,
|
||||
'___sec3'),
|
||||
('General Features', 2, None, '___sec4'),
|
||||
('How do we set it up?', 2, None, '___sec5'),
|
||||
('Decision trees and Regression', 2, None, '___sec6'),
|
||||
('Building a tree, regression', 2, None, '___sec7'),
|
||||
'___sec6'),
|
||||
('General Features', 2, None, '___sec7'),
|
||||
('How do we set it up?', 2, None, '___sec8'),
|
||||
('Decision trees and Regression', 2, None, '___sec9'),
|
||||
('Building a tree, regression', 2, None, '___sec10'),
|
||||
('A top-down approach, recursive binary splitting',
|
||||
2,
|
||||
None,
|
||||
'___sec8'),
|
||||
('Making a tree', 2, None, '___sec9'),
|
||||
('Pruning the tree', 2, None, '___sec10'),
|
||||
('Cost complexity pruning', 2, None, '___sec11'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec12'),
|
||||
('A Classification Tree', 2, None, '___sec13'),
|
||||
('Growing a classification tree', 2, None, '___sec14'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec15'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec16'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec17'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec18'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec19'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec20'),
|
||||
('Computing the Gini index', 2, None, '___sec21'),
|
||||
'___sec11'),
|
||||
('Making a tree', 2, None, '___sec12'),
|
||||
('Pruning the tree', 2, None, '___sec13'),
|
||||
('Cost complexity pruning', 2, None, '___sec14'),
|
||||
('Schematic Regression Procedure', 2, None, '___sec15'),
|
||||
('A Classification Tree', 2, None, '___sec16'),
|
||||
('Growing a classification tree', 2, None, '___sec17'),
|
||||
('Classification tree, how to split nodes', 2, None, '___sec18'),
|
||||
('Visualizing the Tree, Classification', 2, None, '___sec19'),
|
||||
('Visualizing the Tree, The Moons', 2, None, '___sec20'),
|
||||
('Algorithms for Setting up Decision Trees', 2, None, '___sec21'),
|
||||
('The CART algorithm for Classification', 2, None, '___sec22'),
|
||||
('The CART algorithm for Regression', 2, None, '___sec23'),
|
||||
('Computing the Gini index', 2, None, '___sec24'),
|
||||
('Simple Python Code to read in Data and perform Classification',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Computing the Gini Factor', 2, None, '___sec23'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec24'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec25'),
|
||||
'___sec25'),
|
||||
('Computing the Gini Factor', 2, None, '___sec26'),
|
||||
('Entropy and the ID3 algorithm', 2, None, '___sec27'),
|
||||
('Implementing the ID3 Algorithm', 2, None, '___sec28'),
|
||||
('Cancer Data again now with Decision Trees and other Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec26'),
|
||||
('Another example, the moons again', 2, None, '___sec27'),
|
||||
('Playing around with regions', 2, None, '___sec28'),
|
||||
('Regression trees', 2, None, '___sec29'),
|
||||
('Final regressor code', 2, None, '___sec30'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec31'),
|
||||
('Disadvantages', 2, None, '___sec32'),
|
||||
'___sec29'),
|
||||
('Another example, the moons again', 2, None, '___sec30'),
|
||||
('Playing around with regions', 2, None, '___sec31'),
|
||||
('Regression trees', 2, None, '___sec32'),
|
||||
('Final regressor code', 2, None, '___sec33'),
|
||||
('Pros and cons of trees, pros', 2, None, '___sec34'),
|
||||
('Disadvantages', 2, None, '___sec35'),
|
||||
('Ensemble Methods: From a Single Tree to Many Trees and Extreme '
|
||||
'Boosting, Meet the Jungle of Methods',
|
||||
2,
|
||||
None,
|
||||
'___sec33'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec34'),
|
||||
('Bagging', 2, None, '___sec35'),
|
||||
('More bagging', 2, None, '___sec36'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec37'),
|
||||
('Using the Voting Classifier', 2, None, '___sec38'),
|
||||
'___sec36'),
|
||||
('An Overview of Ensemble Methods', 2, None, '___sec37'),
|
||||
('Bagging', 2, None, '___sec38'),
|
||||
('More bagging', 2, None, '___sec39'),
|
||||
('Simple Voting Example, head or tail', 2, None, '___sec40'),
|
||||
('Using the Voting Classifier', 2, None, '___sec41'),
|
||||
('Please, not the moons again! Voting and Bagging',
|
||||
2,
|
||||
None,
|
||||
'___sec39'),
|
||||
('Bagging Examples', 2, None, '___sec40'),
|
||||
'___sec42'),
|
||||
('Bagging Examples', 2, None, '___sec43'),
|
||||
('Making your own Bootstrap: Changing the Level of the Decision '
|
||||
'Tree',
|
||||
2,
|
||||
None,
|
||||
'___sec41')]}
|
||||
'___sec44')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -173,7 +179,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>Oct 26, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Oct 27, 2020</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -225,6 +231,11 @@ to be the most informative ones. The process of finding the <b>most
|
||||
informative</b> feature is done until we accomplish a stopping criteria
|
||||
where we then finally end up in so called <b>leaf nodes</b>.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">Basics of a tree </h2>
|
||||
|
||||
<p>
|
||||
A decision tree is typically divided into a <b>root node</b>, the <b>interior nodes</b>,
|
||||
and the final <b>leaf nodes</b> or just <b>leaves</b>. These entities are then connected by so-called <b>branches</b>.
|
||||
@@ -240,7 +251,23 @@ given some assumptions, make predictions about the target feature value
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec3">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
<h2 id="___sec4">A Sketch of a Tree, Regression problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">A Sketch of a Tree, Classification problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8] -->
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">A typical Decision Tree with its pertinent Jargon, Classification Problem </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/cancer.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -251,7 +278,7 @@ This tree was produced using the Wisconsin cancer data (discussed here as well,
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec4">General Features </h2>
|
||||
<h2 id="___sec7">General Features </h2>
|
||||
|
||||
<p>
|
||||
The overarching approach to decision trees is a top-down approach.
|
||||
@@ -269,7 +296,7 @@ node.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec5">How do we set it up? </h2>
|
||||
<h2 id="___sec8">How do we set it up? </h2>
|
||||
|
||||
<p>
|
||||
In simplified terms, the process of training a decision tree and
|
||||
@@ -287,7 +314,7 @@ Then we are essentially done!
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec6">Decision trees and Regression </h2>
|
||||
<h2 id="___sec9">Decision trees and Regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -383,7 +410,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec7">Building a tree, regression </h2>
|
||||
<h2 id="___sec10">Building a tree, regression </h2>
|
||||
|
||||
<p>
|
||||
There are mainly two steps
|
||||
@@ -411,7 +438,7 @@ within box \( j \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec8">A top-down approach, recursive binary splitting </h2>
|
||||
<h2 id="___sec11">A top-down approach, recursive binary splitting </h2>
|
||||
|
||||
<p>
|
||||
Unfortunately, it is computationally infeasible to consider every
|
||||
@@ -430,7 +457,7 @@ better tree in some future step.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec9">Making a tree </h2>
|
||||
<h2 id="___sec12">Making a tree </h2>
|
||||
|
||||
<p>
|
||||
In order to implement the recursive binary splitting we start by selecting
|
||||
@@ -481,7 +508,7 @@ region contains more than five observations.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec10">Pruning the tree </h2>
|
||||
<h2 id="___sec13">Pruning the tree </h2>
|
||||
|
||||
<p>
|
||||
The above procedure is rather straightforward, but leads often to
|
||||
@@ -500,7 +527,7 @@ parameter \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">Cost complexity pruning </h2>
|
||||
<h2 id="___sec14">Cost complexity pruning </h2>
|
||||
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
|
||||
$$
|
||||
\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
|
||||
@@ -531,7 +558,7 @@ subtree corresponding to \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Schematic Regression Procedure </h2>
|
||||
<h2 id="___sec15">Schematic Regression Procedure </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -557,7 +584,7 @@ subtree corresponding to \( \alpha \).
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">A Classification Tree </h2>
|
||||
<h2 id="___sec16">A Classification Tree </h2>
|
||||
|
||||
<p>
|
||||
A classification tree is very similar to a regression tree, except
|
||||
@@ -576,7 +603,7 @@ fall into that region.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">Growing a classification tree </h2>
|
||||
<h2 id="___sec17">Growing a classification tree </h2>
|
||||
|
||||
<p>
|
||||
The task of growing a
|
||||
@@ -600,7 +627,7 @@ than is the classification error rate.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">Classification tree, how to split nodes </h2>
|
||||
<h2 id="___sec18">Classification tree, how to split nodes </h2>
|
||||
|
||||
<p>
|
||||
If our targets are the outcome of a classification process that takes
|
||||
@@ -650,7 +677,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">Visualizing the Tree, Classification </h2>
|
||||
<h2 id="___sec19">Visualizing the Tree, Classification </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -691,7 +718,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">Visualizing the Tree, The Moons </h2>
|
||||
<h2 id="___sec20">Visualizing the Tree, The Moons </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -723,7 +750,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec18">Algorithms for Setting up Decision Trees </h2>
|
||||
<h2 id="___sec21">Algorithms for Setting up Decision Trees </h2>
|
||||
|
||||
<p>
|
||||
Two algorithms stand out in the set up of decision trees:
|
||||
@@ -741,7 +768,7 @@ in two branches.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec19">The CART algorithm for Classification </h2>
|
||||
<h2 id="___sec22">The CART algorithm for Classification </h2>
|
||||
|
||||
<p>
|
||||
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
|
||||
@@ -768,7 +795,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec20">The CART algorithm for Regression </h2>
|
||||
<h2 id="___sec23">The CART algorithm for Regression </h2>
|
||||
|
||||
<p>
|
||||
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
|
||||
@@ -796,7 +823,7 @@ just like for classification tasks, is prone to overfitting.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Computing the Gini index </h2>
|
||||
<h2 id="___sec24">Computing the Gini index </h2>
|
||||
|
||||
<p>
|
||||
The example we will look at is a classical one in many Machine
|
||||
@@ -836,7 +863,7 @@ The table here summarizes the various attributes and
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">Simple Python Code to read in Data and perform Classification </h2>
|
||||
<h2 id="___sec25">Simple Python Code to read in Data and perform Classification </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -912,7 +939,7 @@ os<span style="color: #666666">.</span>system(cmd)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec23">Computing the Gini Factor </h2>
|
||||
<h2 id="___sec26">Computing the Gini Factor </h2>
|
||||
|
||||
<p>
|
||||
The above functions (gini, entropy and misclassification error) are
|
||||
@@ -990,7 +1017,7 @@ split <span style="color: #666666">=</span> get_split(dataset)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec24">Entropy and the ID3 algorithm </h2>
|
||||
<h2 id="___sec27">Entropy and the ID3 algorithm </h2>
|
||||
|
||||
<p>
|
||||
ID3, learns decision trees by constructing
|
||||
@@ -1026,7 +1053,7 @@ attributes at each step while growing the tree.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec25">Implementing the ID3 Algorithm </h2>
|
||||
<h2 id="___sec28">Implementing the ID3 Algorithm </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1222,7 +1249,7 @@ attributes at each step while growing the tree.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec26">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<h2 id="___sec29">Cancer Data again now with Decision Trees and other Methods </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1271,7 +1298,7 @@ deep_tree_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec27">Another example, the moons again </h2>
|
||||
<h2 id="___sec30">Another example, the moons again </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1343,7 +1370,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec28">Playing around with regions </h2>
|
||||
<h2 id="___sec31">Playing around with regions </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1371,7 +1398,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec29">Regression trees </h2>
|
||||
<h2 id="___sec32">Regression trees </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1393,7 +1420,7 @@ tree_reg<span style="color: #666666">.</span>fit(X, y)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec30">Final regressor code </h2>
|
||||
<h2 id="___sec33">Final regressor code </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1471,7 +1498,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec31">Pros and cons of trees, pros </h2>
|
||||
<h2 id="___sec34">Pros and cons of trees, pros </h2>
|
||||
|
||||
<ul>
|
||||
<li> White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)</li>
|
||||
@@ -1485,7 +1512,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec32">Disadvantages </h2>
|
||||
<h2 id="___sec35">Disadvantages </h2>
|
||||
|
||||
<ul>
|
||||
<li> Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches</li>
|
||||
@@ -1504,7 +1531,7 @@ trees can be substantially improved.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec33">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
<h2 id="___sec36">Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods </h2>
|
||||
|
||||
<p>
|
||||
As stated above and seen in many of the examples discussed here about
|
||||
@@ -1531,7 +1558,7 @@ We discuss these methods here.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec34">An Overview of Ensemble Methods </h2>
|
||||
<h2 id="___sec37">An Overview of Ensemble Methods </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="DataFiles/ensembleoverview.png" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -1539,7 +1566,7 @@ We discuss these methods here.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec35">Bagging </h2>
|
||||
<h2 id="___sec38">Bagging </h2>
|
||||
|
||||
<p>
|
||||
The <b>plain</b> decision trees suffer from high
|
||||
@@ -1558,7 +1585,7 @@ learning method.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec36">More bagging </h2>
|
||||
<h2 id="___sec39">More bagging </h2>
|
||||
|
||||
<p>
|
||||
Bagging typically results in improved accuracy
|
||||
@@ -1587,7 +1614,7 @@ predictor, averaged over all \( B \) trees.
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec37">Simple Voting Example, head or tail </h2>
|
||||
<h2 id="___sec40">Simple Voting Example, head or tail </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1608,7 +1635,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec38">Using the Voting Classifier </h2>
|
||||
<h2 id="___sec41">Using the Voting Classifier </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -1659,7 +1686,7 @@ voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec39">Please, not the moons again! Voting and Bagging </h2>
|
||||
<h2 id="___sec42">Please, not the moons again! Voting and Bagging </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1718,7 +1745,7 @@ voting_clf<span style="color: #666666">.</span>fit(X_train, y_train)
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec40">Bagging Examples </h2>
|
||||
<h2 id="___sec43">Bagging Examples </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1780,7 +1807,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec41">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
<h2 id="___sec44">Making your own Bootstrap: Changing the Level of the Decision Tree </h2>
|
||||
|
||||
<p>
|
||||
Let us bring up our good old boostrap example from the linear regression lectures. We change the linerar regression algorithm with
|
||||
|
||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Oct 26, 2020**\n",
|
||||
"Date: **Oct 27, 2020**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -55,7 +55,7 @@
|
||||
"informative** feature is done until we accomplish a stopping criteria\n",
|
||||
"where we then finally end up in so called **leaf nodes**. \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Basics of a tree\n",
|
||||
"\n",
|
||||
"A decision tree is typically divided into a **root node**, the **interior nodes**,\n",
|
||||
"and the final **leaf nodes** or just **leaves**. These entities are then connected by so-called **branches**.\n",
|
||||
@@ -67,6 +67,16 @@
|
||||
"given some assumptions, make predictions about the target feature value\n",
|
||||
"(class) of unseen query instances.\n",
|
||||
"\n",
|
||||
"## A Sketch of a Tree, Regression problem\n",
|
||||
"\n",
|
||||
"<!-- FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8] -->\n",
|
||||
"\n",
|
||||
"## A Sketch of a Tree, Classification problem\n",
|
||||
"\n",
|
||||
"<!-- FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8] -->\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## A typical Decision Tree with its pertinent Jargon, Classification Problem\n",
|
||||
"\n",
|
||||
"<!-- dom:FIGURE: [DataFiles/cancer.png, width=600 frac=0.8] -->\n",
|
||||
|
||||
@@ -44,7 +44,8 @@ to be the most informative ones. The process of finding the _most
|
||||
informative_ feature is done until we accomplish a stopping criteria
|
||||
where we then finally end up in so called _leaf nodes_.
|
||||
|
||||
|
||||
!split
|
||||
===== Basics of a tree =====
|
||||
|
||||
A decision tree is typically divided into a _root node_, the _interior nodes_,
|
||||
and the final _leaf nodes_ or just _leaves_. These entities are then connected by so-called _branches_.
|
||||
@@ -56,6 +57,18 @@ learned the underlying structure of the training data and hence can,
|
||||
given some assumptions, make predictions about the target feature value
|
||||
(class) of unseen query instances.
|
||||
|
||||
!split
|
||||
===== A Sketch of a Tree, Regression problem =====
|
||||
|
||||
#FIGURE: [DataFiles/Regsimpletree.png, width=600 frac=0.8]
|
||||
|
||||
!split
|
||||
===== A Sketch of a Tree, Classification problem =====
|
||||
|
||||
#FIGURE: [DataFiles/Classimpletree.png, width=600 frac=0.8]
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== A typical Decision Tree with its pertinent Jargon, Classification Problem =====
|
||||
|
||||
|
||||
Reference in New Issue
Block a user