added datafiles

This commit is contained in:
mhjensen
2019-10-31 06:40:25 +01:00
parent b5a10fb2dc
commit 415fcf3f0c
14 changed files with 3431 additions and 0 deletions
@@ -0,0 +1,249 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0032"></a>
<!-- !split -->
<h2 id="___sec31" class="anchor">Simple 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>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">&lt;</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">&quot;k--&quot;</span>, linewidth<span style="color: #666666">=2</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">&quot;51%&quot;</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">&quot;k-&quot;</span>, label<span style="color: #666666">=</span><span style="color: #BA2121">&quot;50%&quot;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&quot;Number of coin tosses&quot;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&quot;Heads ratio&quot;</span>)
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=</span><span style="color: #BA2121">&quot;lower right&quot;</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>])
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._DecisionTrees-bs031.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs024.html">25</a></li>
<li><a href="._DecisionTrees-bs025.html">26</a></li>
<li><a href="._DecisionTrees-bs026.html">27</a></li>
<li><a href="._DecisionTrees-bs027.html">28</a></li>
<li><a href="._DecisionTrees-bs028.html">29</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li class="active"><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs033.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,279 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0033"></a>
<!-- !split -->
<h2 id="___sec32" class="anchor">Bagging Example </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">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(solver<span style="color: #666666">=</span><span style="color: #BA2121">&quot;liblinear&quot;</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">&quot;auto&quot;</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">&#39;lr&#39;</span>, log_clf), (<span style="color: #BA2121">&#39;rf&#39;</span>, rnd_clf), (<span style="color: #BA2121">&#39;svc&#39;</span>, svm_clf)],
voting<span style="color: #666666">=</span><span style="color: #BA2121">&#39;hard&#39;</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; font-weight: bold">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">&quot;liblinear&quot;</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">&quot;auto&quot;</span>, probability<span style="color: #666666">=</span><span style="color: #008000">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">&#39;lr&#39;</span>, log_clf), (<span style="color: #BA2121">&#39;rf&#39;</span>, rnd_clf), (<span style="color: #BA2121">&#39;svc&#39;</span>, svm_clf)],
voting<span style="color: #666666">=</span><span style="color: #BA2121">&#39;soft&#39;</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; font-weight: bold">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">
<li><a href="._DecisionTrees-bs032.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs025.html">26</a></li>
<li><a href="._DecisionTrees-bs026.html">27</a></li>
<li><a href="._DecisionTrees-bs027.html">28</a></li>
<li><a href="._DecisionTrees-bs028.html">29</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li class="active"><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs034.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,271 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0034"></a>
<!-- !split -->
<h2 id="___sec33" class="anchor">Random forests </h2>
<p>
Random forests provide an improvement over bagged trees by way of a
small tweak that decorrelates the trees.
<p>
As in bagging, we build a
number of decision trees on bootstrapped training samples. But when
building these decision trees, each time a split in a tree is
considered, a random sample of \( m \) predictors is chosen as split
candidates from the full set of \( p \) predictors. The split is allowed to
use only one of those \( m \) predictors.
<p>
A fresh sample of \( m \) predictors is
taken at each split, and typically we choose
$$
m\approx \sqrt{p}.
$$
<p>
In building a random forest, at
each split in the tree, the algorithm is not even allowed to consider
a majority of the available predictors.
<p>
The reason for this is rather clever. Suppose that there is one very
strong predictor in the data set, along with a number of other
moderately strong predictors. Then in the collection of bagged
variable importance random forest trees, most or all of the trees will
use this strong predictor in the top split. Consequently, all of the
bagged trees will look quite similar to each other. Hence the
predictions from the bagged trees will be highly correlated.
Unfortunately, averaging many highly correlated quantities does not
lead to as large of a reduction in variance as averaging many
uncorrelated quanti- ties. In particular, this means that bagging will
not lead to a substantial reduction in variance over a single tree in
this setting.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._DecisionTrees-bs033.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs026.html">27</a></li>
<li><a href="._DecisionTrees-bs027.html">28</a></li>
<li><a href="._DecisionTrees-bs028.html">29</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li class="active"><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs035.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,244 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0035"></a>
<!-- !split -->
<h2 id="___sec34" class="anchor">A simple scikit-learn example </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> LabelEncoder
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> cross_validate
<span style="color: #408080; font-style: italic"># Data set not specificied</span>
X <span style="color: #666666">=</span> dataset<span style="color: #666666">.</span>XXX
Y <span style="color: #666666">=</span> dataset<span style="color: #666666">.</span>YYY
<span style="color: #408080; font-style: italic">#Instantiate the model with 100 trees and entropy as splitting criteria</span>
Random_Forest_model <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=100</span>,criterion<span style="color: #666666">=</span><span style="color: #BA2121">&quot;entropy&quot;</span>)
<span style="color: #408080; font-style: italic">#Cross validation</span>
accuracy <span style="color: #666666">=</span> cross_validate(Random_Forest_model,X,Y,cv<span style="color: #666666">=10</span>)[<span style="color: #BA2121">&#39;test_score&#39;</span>]
</pre></div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._DecisionTrees-bs034.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs027.html">28</a></li>
<li><a href="._DecisionTrees-bs028.html">29</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li class="active"><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs036.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,283 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0036"></a>
<!-- !split -->
<h2 id="___sec35" class="anchor">Please, not 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.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">&#39;lr&#39;</span>, log_clf), (<span style="color: #BA2121">&#39;rf&#39;</span>, rnd_clf), (<span style="color: #BA2121">&#39;svc&#39;</span>, svm_clf)],
voting<span style="color: #666666">=</span><span style="color: #BA2121">&#39;hard&#39;</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; font-weight: bold">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">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">&#39;lr&#39;</span>, log_clf), (<span style="color: #BA2121">&#39;rf&#39;</span>, rnd_clf), (<span style="color: #BA2121">&#39;svc&#39;</span>, svm_clf)],
voting<span style="color: #666666">=</span><span style="color: #BA2121">&#39;soft&#39;</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; font-weight: bold">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">
<li><a href="._DecisionTrees-bs035.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs028.html">29</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li class="active"><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs037.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,285 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs038.html#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0037"></a>
<!-- !split -->
<h2 id="___sec36" class="anchor">Bagging examples </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">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; font-weight: bold">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; font-weight: bold">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">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">&#39;#fafab0&#39;</span>,<span style="color: #BA2121">&#39;#9898ff&#39;</span>,<span style="color: #BA2121">&#39;#a0faa0&#39;</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">&#39;#7d7d58&#39;</span>,<span style="color: #BA2121">&#39;#4c4c7f&#39;</span>,<span style="color: #BA2121">&#39;#507d50&#39;</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">&quot;yo&quot;</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">&quot;bs&quot;</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&quot;$x_1$&quot;</span>, fontsize<span style="color: #666666">=18</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r&quot;$x_2$&quot;</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">&quot;Decision Tree&quot;</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">&quot;Decision Trees with Bagging&quot;</span>, 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 -->
<ul class="pagination">
<li><a href="._DecisionTrees-bs036.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs029.html">30</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li class="active"><a href="._DecisionTrees-bs037.html">38</a></li>
<li><a href="._DecisionTrees-bs038.html">39</a></li>
<li><a href="._DecisionTrees-bs038.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,245 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Data Analysis and Machine Learning: From Decision Trees to Forests and all that">
<title>Data Analysis and Machine Learning: From Decision Trees to Forests and all that</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('Decision trees, overarching aims', 2, None, '___sec0'),
('A typical Decision Tree with its pertinent Jargon, '
'Classification Problem',
2,
None,
'___sec1'),
('A typical Decision Tree with its pertinent Jargon, Regeression '
'Problem',
2,
None,
'___sec2'),
('General Features', 2, None, '___sec3'),
('How do we set it up?', 2, None, '___sec4'),
('Decision trees and Regression', 2, None, '___sec5'),
('Building a tree, regression', 2, None, '___sec6'),
('A top-down approach, recursive binary splitting',
2,
None,
'___sec7'),
('Making a tree', 2, None, '___sec8'),
('Pruning the tree', 2, None, '___sec9'),
('Cost complexity pruning', 2, None, '___sec10'),
('Schematic Regression Procedure', 2, None, '___sec11'),
('A Classification Tree', 2, None, '___sec12'),
('Growing a classification tree', 2, None, '___sec13'),
('Classification tree, how to split nodes', 2, None, '___sec14'),
('Visualizing the Tree, Classification', 2, None, '___sec15'),
('Visualizing the Tree, The Moons', 2, None, '___sec16'),
('Computing the Gini index', 2, None, '___sec17'),
('Simple Python Code to read in Data', 2, None, '___sec18'),
('Computing the Gini Factor', 2, None, '___sec19'),
('Entropy and the ID3 algorithm', 2, None, '___sec20'),
('Implementing the ID3 Algorithm', 2, None, '___sec21'),
('Cancer Data again now with Decision Trees and other Methods',
2,
None,
'___sec22'),
('Another example, the moons again', 2, None, '___sec23'),
('Playing around with regions', 2, None, '___sec24'),
('Regression trees', 2, None, '___sec25'),
('Final regressor code', 2, None, '___sec26'),
('Pros and cons of trees, pros', 2, None, '___sec27'),
('Disadvantages', 2, None, '___sec28'),
('Bagging', 2, None, '___sec29'),
('More bagging', 2, None, '___sec30'),
('Simple example, head or tail', 2, None, '___sec31'),
('Bagging Example', 2, None, '___sec32'),
('Random forests', 2, None, '___sec33'),
('A simple scikit-learn example', 2, None, '___sec34'),
('Please, not the moons again!', 2, None, '___sec35'),
('Bagging examples', 2, None, '___sec36'),
('Then random forests', 2, None, '___sec37')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="DecisionTrees-bs.html">Data Analysis and Machine Learning: From Decision Trees to Forests and all that</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs001.html#___sec0" style="font-size: 80%;">Decision trees, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs002.html#___sec1" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Classification Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs003.html#___sec2" style="font-size: 80%;">A typical Decision Tree with its pertinent Jargon, Regeression Problem</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs004.html#___sec3" style="font-size: 80%;">General Features</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs005.html#___sec4" style="font-size: 80%;">How do we set it up?</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs006.html#___sec5" style="font-size: 80%;">Decision trees and Regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs007.html#___sec6" style="font-size: 80%;">Building a tree, regression</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs008.html#___sec7" style="font-size: 80%;">A top-down approach, recursive binary splitting</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs009.html#___sec8" style="font-size: 80%;">Making a tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs010.html#___sec9" style="font-size: 80%;">Pruning the tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs011.html#___sec10" style="font-size: 80%;">Cost complexity pruning</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs012.html#___sec11" style="font-size: 80%;">Schematic Regression Procedure</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs013.html#___sec12" style="font-size: 80%;">A Classification Tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs014.html#___sec13" style="font-size: 80%;">Growing a classification tree</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Classification tree, how to split nodes</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs022.html#___sec21" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs023.html#___sec22" style="font-size: 80%;">Cancer Data again now with Decision Trees and other Methods</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs024.html#___sec23" style="font-size: 80%;">Another example, the moons again</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs025.html#___sec24" style="font-size: 80%;">Playing around with regions</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs026.html#___sec25" style="font-size: 80%;">Regression trees</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs027.html#___sec26" style="font-size: 80%;">Final regressor code</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs028.html#___sec27" style="font-size: 80%;">Pros and cons of trees, pros</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs029.html#___sec28" style="font-size: 80%;">Disadvantages</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs030.html#___sec29" style="font-size: 80%;">Bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs031.html#___sec30" style="font-size: 80%;">More bagging</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs032.html#___sec31" style="font-size: 80%;">Simple example, head or tail</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs033.html#___sec32" style="font-size: 80%;">Bagging Example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs034.html#___sec33" style="font-size: 80%;">Random forests</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs035.html#___sec34" style="font-size: 80%;">A simple scikit-learn example</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs036.html#___sec35" style="font-size: 80%;">Please, not the moons again!</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs037.html#___sec36" style="font-size: 80%;">Bagging examples</a></li>
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">Then random forests</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0038"></a>
<!-- !split -->
<h2 id="___sec37" class="anchor">Then random forests </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf <span style="color: #666666">=</span> BaggingClassifier(
DecisionTreeClassifier(splitter<span style="color: #666666">=</span><span style="color: #BA2121">&quot;random&quot;</span>, max_leaf_nodes<span style="color: #666666">=16</span>, random_state<span style="color: #666666">=42</span>),
n_estimators<span style="color: #666666">=500</span>, max_samples<span style="color: #666666">=1.0</span>, bootstrap<span style="color: #666666">=</span><span style="color: #008000">True</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
</pre></div>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>bag_clf<span style="color: #666666">.</span>fit(X_train, y_train)
y_pred <span style="color: #666666">=</span> bag_clf<span style="color: #666666">.</span>predict(X_test)
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> RandomForestClassifier
rnd_clf <span style="color: #666666">=</span> RandomForestClassifier(n_estimators<span style="color: #666666">=500</span>, max_leaf_nodes<span style="color: #666666">=16</span>, n_jobs<span style="color: #666666">=-1</span>, random_state<span style="color: #666666">=42</span>)
rnd_clf<span style="color: #666666">.</span>fit(X_train, y_train)
y_pred_rf <span style="color: #666666">=</span> rnd_clf<span style="color: #666666">.</span>predict(X_test)
np<span style="color: #666666">.</span>sum(y_pred <span style="color: #666666">==</span> y_pred_rf) <span style="color: #666666">/</span> <span style="color: #008000">len</span>(y_pred)
</pre></div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._DecisionTrees-bs037.html">&laquo;</a></li>
<li><a href="._DecisionTrees-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._DecisionTrees-bs030.html">31</a></li>
<li><a href="._DecisionTrees-bs031.html">32</a></li>
<li><a href="._DecisionTrees-bs032.html">33</a></li>
<li><a href="._DecisionTrees-bs033.html">34</a></li>
<li><a href="._DecisionTrees-bs034.html">35</a></li>
<li><a href="._DecisionTrees-bs035.html">36</a></li>
<li><a href="._DecisionTrees-bs036.html">37</a></li>
<li><a href="._DecisionTrees-bs037.html">38</a></li>
<li class="active"><a href="._DecisionTrees-bs038.html">39</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,57 @@
digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="worst perimeter <= 106.05\ngini = 0.465\nsamples = 426\nvalue = [[269, 157]\n[157, 269]]", fillcolor="#e5813908"] ;
1 [label="worst concave points <= 0.159\ngini = 0.067\nsamples = 259\nvalue = [[250, 9]\n[9, 250]]", fillcolor="#e58139db"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="worst concave points <= 0.135\ngini = 0.031\nsamples = 253\nvalue = [[249, 4]\n[4, 249]]", fillcolor="#e58139ee"] ;
1 -> 2 ;
3 [label="radius error <= 0.643\ngini = 0.008\nsamples = 242\nvalue = [[241, 1]\n[1, 241]]", fillcolor="#e58139fb"] ;
2 -> 3 ;
4 [label="gini = 0.0\nsamples = 239\nvalue = [[239, 0]\n[0, 239]]", fillcolor="#e58139ff"] ;
3 -> 4 ;
5 [label="worst symmetry <= 0.208\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#e5813913"] ;
3 -> 5 ;
6 [label="gini = 0.0\nsamples = 1\nvalue = [[0, 1]\n[1, 0]]", fillcolor="#e58139ff"] ;
5 -> 6 ;
7 [label="gini = 0.0\nsamples = 2\nvalue = [[2, 0]\n[0, 2]]", fillcolor="#e58139ff"] ;
5 -> 7 ;
8 [label="worst texture <= 29.455\ngini = 0.397\nsamples = 11\nvalue = [[8, 3]\n[3, 8]]", fillcolor="#e581392c"] ;
2 -> 8 ;
9 [label="gini = 0.0\nsamples = 8\nvalue = [[8, 0]\n[0, 8]]", fillcolor="#e58139ff"] ;
8 -> 9 ;
10 [label="gini = 0.0\nsamples = 3\nvalue = [[0, 3]\n[3, 0]]", fillcolor="#e58139ff"] ;
8 -> 10 ;
11 [label="mean texture <= 16.22\ngini = 0.278\nsamples = 6\nvalue = [[1, 5]\n[5, 1]]", fillcolor="#e581396b"] ;
1 -> 11 ;
12 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ;
11 -> 12 ;
13 [label="gini = 0.0\nsamples = 5\nvalue = [[0, 5]\n[5, 0]]", fillcolor="#e58139ff"] ;
11 -> 13 ;
14 [label="worst texture <= 20.645\ngini = 0.202\nsamples = 167\nvalue = [[19, 148]\n[148, 19]]", fillcolor="#e5813994"] ;
0 -> 14 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
15 [label="worst radius <= 17.74\ngini = 0.375\nsamples = 16\nvalue = [[12, 4]\n[4, 12]]", fillcolor="#e5813938"] ;
14 -> 15 ;
16 [label="gini = 0.0\nsamples = 11\nvalue = [[11, 0]\n[0, 11]]", fillcolor="#e58139ff"] ;
15 -> 16 ;
17 [label="mean texture <= 13.745\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#e5813955"] ;
15 -> 17 ;
18 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ;
17 -> 18 ;
19 [label="gini = 0.0\nsamples = 4\nvalue = [[0, 4]\n[4, 0]]", fillcolor="#e58139ff"] ;
17 -> 19 ;
20 [label="mean concave points <= 0.049\ngini = 0.088\nsamples = 151\nvalue = [[7, 144]\n[144, 7]]", fillcolor="#e58139d0"] ;
14 -> 20 ;
21 [label="concave points error <= 0.01\ngini = 0.48\nsamples = 15\nvalue = [[6, 9]\n[9, 6]]", fillcolor="#e5813900"] ;
20 -> 21 ;
22 [label="gini = 0.0\nsamples = 9\nvalue = [[0, 9]\n[9, 0]]", fillcolor="#e58139ff"] ;
21 -> 22 ;
23 [label="gini = 0.0\nsamples = 6\nvalue = [[6, 0]\n[0, 6]]", fillcolor="#e58139ff"] ;
21 -> 23 ;
24 [label="worst smoothness <= 0.096\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e58139f7"] ;
20 -> 24 ;
25 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ;
24 -> 25 ;
26 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139ff"] ;
24 -> 26 ;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

@@ -0,0 +1,15 @@
Outlook,Temperature,Humidity,Wind,Ride
0,0,0,0,0
0,0,0,1,1
1,0,0,0,1
2,1,0,0,1
2,2,1,0,1
2,2,1,1,0
1,2,1,1,1
0,1,0,0,0
0,2,1,0,1
2,1,1,0,1
0,1,1,1,1
1,1,0,1,1
1,0,1,0,1
2,1,0,1,0
1 Outlook Temperature Humidity Wind Ride
2 0 0 0 0 0
3 0 0 0 1 1
4 1 0 0 0 1
5 2 1 0 0 1
6 2 2 1 0 1
7 2 2 1 1 0
8 1 2 1 1 1
9 0 1 0 0 0
10 0 2 1 0 1
11 2 1 1 0 1
12 0 1 1 1 1
13 1 1 0 1 1
14 1 0 1 0 1
15 2 1 0 1 0
@@ -0,0 +1,15 @@
Outlook,Temperature,Humidity,Wind,Ride
Sunny,Hot,High,Weak,0
Sunny,Hot,High,Strong,1
Overcast,Hot,High,Weak,1
Rain,Mild,High,Weak,1
Rain,Cool,Normal,Weak,1
Rain,Cool,Normal,Strong,0
Overcast,Cool,Normal,Strong,1
Sunny,Mild,High,Weak,0
Sunny,Cool,Normal,Weak,1
Rain,Mild,Normal,Weak,1
Sunny,Mild,Normal,Strong,1
Overcast,Mild,High,Strong,1
Overcast,Hot,Normal,Weak,1
Rain,Mild,High,Strong,0
@@ -0,0 +1,15 @@
Day,Outlook,Temperature,Humidity,Wind,Ride
1,Sunny,Hot,High,Weak,0
2,Sunny,Hot,High,Strong,1
3,Overcast,Hot,High,Weak,1
4,Rain,Mild,High,Weak,1
5,Rain,Cool,Normal,Weak,1
6,Rain,Cool,Normal,Strong,0
7,Overcast,Cool,Normal,Strong,1
8,Sunny,Mild,High,Weak,0
9,Sunny,Cool,Normal,Weak,1
10,Rain,Mild,Normal,Weak,1
11,Sunny,Mild,Normal,Strong,1
12,Overcast,Mild,High,Strong,1
13,Overcast,Hot,Normal,Weak,1
14,Rain,Mild,High,Strong,0
1 Day Outlook Temperature Humidity Wind Ride
2 1 Sunny Hot High Weak 0
3 2 Sunny Hot High Strong 1
4 3 Overcast Hot High Weak 1
5 4 Rain Mild High Weak 1
6 5 Rain Cool Normal Weak 1
7 6 Rain Cool Normal Strong 0
8 7 Overcast Cool Normal Strong 1
9 8 Sunny Mild High Weak 0
10 9 Sunny Cool Normal Weak 1
11 10 Rain Mild Normal Weak 1
12 11 Sunny Mild Normal Strong 1
13 12 Overcast Mild High Strong 1
14 13 Overcast Hot Normal Weak 1
15 14 Rain Mild High Strong 0
@@ -0,0 +1,101 @@
aardvark,1,0,0,1,0,0,1,1,1,1,0,0,4,0,0,1,1
antelope,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
bass,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,4
bear,1,0,0,1,0,0,1,1,1,1,0,0,4,0,0,1,1
boar,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
buffalo,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
calf,1,0,0,1,0,0,0,1,1,1,0,0,4,1,1,1,1
carp,0,0,1,0,0,1,0,1,1,0,0,1,0,1,1,0,4
catfish,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,4
cavy,1,0,0,1,0,0,0,1,1,1,0,0,4,0,1,0,1
cheetah,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
chicken,0,1,1,0,1,0,0,0,1,1,0,0,2,1,1,0,2
chub,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,4
clam,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,7
crab,0,0,1,0,0,1,1,0,0,0,0,0,4,0,0,0,7
crayfish,0,0,1,0,0,1,1,0,0,0,0,0,6,0,0,0,7
crow,0,1,1,0,1,0,1,0,1,1,0,0,2,1,0,0,2
deer,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
dogfish,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,1,4
dolphin,0,0,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1
dove,0,1,1,0,1,0,0,0,1,1,0,0,2,1,1,0,2
duck,0,1,1,0,1,1,0,0,1,1,0,0,2,1,0,0,2
elephant,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
flamingo,0,1,1,0,1,0,0,0,1,1,0,0,2,1,0,1,2
flea,0,0,1,0,0,0,0,0,0,1,0,0,6,0,0,0,6
frog,0,0,1,0,0,1,1,1,1,1,0,0,4,0,0,0,5
frog,0,0,1,0,0,1,1,1,1,1,1,0,4,0,0,0,5
fruitbat,1,0,0,1,1,0,0,1,1,1,0,0,2,1,0,0,1
giraffe,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
girl,1,0,0,1,0,0,1,1,1,1,0,0,2,0,1,1,1
gnat,0,0,1,0,1,0,0,0,0,1,0,0,6,0,0,0,6
goat,1,0,0,1,0,0,0,1,1,1,0,0,4,1,1,1,1
gorilla,1,0,0,1,0,0,0,1,1,1,0,0,2,0,0,1,1
gull,0,1,1,0,1,1,1,0,1,1,0,0,2,1,0,0,2
haddock,0,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,4
hamster,1,0,0,1,0,0,0,1,1,1,0,0,4,1,1,0,1
hare,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,0,1
hawk,0,1,1,0,1,0,1,0,1,1,0,0,2,1,0,0,2
herring,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,4
honeybee,1,0,1,0,1,0,0,0,0,1,1,0,6,0,1,0,6
housefly,1,0,1,0,1,0,0,0,0,1,0,0,6,0,0,0,6
kiwi,0,1,1,0,0,0,1,0,1,1,0,0,2,1,0,0,2
ladybird,0,0,1,0,1,0,1,0,0,1,0,0,6,0,0,0,6
lark,0,1,1,0,1,0,0,0,1,1,0,0,2,1,0,0,2
leopard,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
lion,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
lobster,0,0,1,0,0,1,1,0,0,0,0,0,6,0,0,0,7
lynx,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
mink,1,0,0,1,0,1,1,1,1,1,0,0,4,1,0,1,1
mole,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,0,1
mongoose,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
moth,1,0,1,0,1,0,0,0,0,1,0,0,6,0,0,0,6
newt,0,0,1,0,0,1,1,1,1,1,0,0,4,1,0,0,5
octopus,0,0,1,0,0,1,1,0,0,0,0,0,8,0,0,1,7
opossum,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,0,1
oryx,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,1,1
ostrich,0,1,1,0,0,0,0,0,1,1,0,0,2,1,0,1,2
parakeet,0,1,1,0,1,0,0,0,1,1,0,0,2,1,1,0,2
penguin,0,1,1,0,0,1,1,0,1,1,0,0,2,1,0,1,2
pheasant,0,1,1,0,1,0,0,0,1,1,0,0,2,1,0,0,2
pike,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,1,4
piranha,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,4
pitviper,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0,0,3
platypus,1,0,1,1,0,1,1,0,1,1,0,0,4,1,0,1,1
polecat,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
pony,1,0,0,1,0,0,0,1,1,1,0,0,4,1,1,1,1
porpoise,0,0,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1
puma,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
pussycat,1,0,0,1,0,0,1,1,1,1,0,0,4,1,1,1,1
raccoon,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
reindeer,1,0,0,1,0,0,0,1,1,1,0,0,4,1,1,1,1
rhea,0,1,1,0,0,0,1,0,1,1,0,0,2,1,0,1,2
scorpion,0,0,0,0,0,0,1,0,0,1,1,0,8,1,0,0,7
seahorse,0,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,4
seal,1,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,1
sealion,1,0,0,1,0,1,1,1,1,1,0,1,2,1,0,1,1
seasnake,0,0,0,0,0,1,1,1,1,0,1,0,0,1,0,0,3
seawasp,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,7
skimmer,0,1,1,0,1,1,1,0,1,1,0,0,2,1,0,0,2
skua,0,1,1,0,1,1,1,0,1,1,0,0,2,1,0,0,2
slowworm,0,0,1,0,0,0,1,1,1,1,0,0,0,1,0,0,3
slug,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,7
sole,0,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,4
sparrow,0,1,1,0,1,0,0,0,1,1,0,0,2,1,0,0,2
squirrel,1,0,0,1,0,0,0,1,1,1,0,0,2,1,0,0,1
starfish,0,0,1,0,0,1,1,0,0,0,0,0,5,0,0,0,7
stingray,0,0,1,0,0,1,1,1,1,0,1,1,0,1,0,1,4
swan,0,1,1,0,1,1,0,0,1,1,0,0,2,1,0,1,2
termite,0,0,1,0,0,0,0,0,0,1,0,0,6,0,0,0,6
toad,0,0,1,0,0,1,0,1,1,1,0,0,4,0,0,0,5
tortoise,0,0,1,0,0,0,0,0,1,1,0,0,4,1,0,1,3
tuatara,0,0,1,0,0,0,1,1,1,1,0,0,4,1,0,0,3
tuna,0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,1,4
vampire,1,0,0,1,1,0,0,1,1,1,0,0,2,1,0,0,1
vole,1,0,0,1,0,0,0,1,1,1,0,0,4,1,0,0,1
vulture,0,1,1,0,1,0,1,0,1,1,0,0,2,1,0,1,2
wallaby,1,0,0,1,0,0,0,1,1,1,0,0,2,1,0,1,1
wasp,1,0,1,0,1,0,0,0,0,1,1,0,6,0,0,0,6
wolf,1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1,1
worm,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,7
wren,0,1,1,0,1,0,0,0,1,1,0,0,2,1,0,0,2
1 aardvark 1 0 0 1 0 0 1 1 1 1 0 0 4 0 0 1 1
2 antelope 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
3 bass 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 4
4 bear 1 0 0 1 0 0 1 1 1 1 0 0 4 0 0 1 1
5 boar 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
6 buffalo 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
7 calf 1 0 0 1 0 0 0 1 1 1 0 0 4 1 1 1 1
8 carp 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 4
9 catfish 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 4
10 cavy 1 0 0 1 0 0 0 1 1 1 0 0 4 0 1 0 1
11 cheetah 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
12 chicken 0 1 1 0 1 0 0 0 1 1 0 0 2 1 1 0 2
13 chub 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 4
14 clam 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 7
15 crab 0 0 1 0 0 1 1 0 0 0 0 0 4 0 0 0 7
16 crayfish 0 0 1 0 0 1 1 0 0 0 0 0 6 0 0 0 7
17 crow 0 1 1 0 1 0 1 0 1 1 0 0 2 1 0 0 2
18 deer 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
19 dogfish 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 1 4
20 dolphin 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 1
21 dove 0 1 1 0 1 0 0 0 1 1 0 0 2 1 1 0 2
22 duck 0 1 1 0 1 1 0 0 1 1 0 0 2 1 0 0 2
23 elephant 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
24 flamingo 0 1 1 0 1 0 0 0 1 1 0 0 2 1 0 1 2
25 flea 0 0 1 0 0 0 0 0 0 1 0 0 6 0 0 0 6
26 frog 0 0 1 0 0 1 1 1 1 1 0 0 4 0 0 0 5
27 frog 0 0 1 0 0 1 1 1 1 1 1 0 4 0 0 0 5
28 fruitbat 1 0 0 1 1 0 0 1 1 1 0 0 2 1 0 0 1
29 giraffe 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
30 girl 1 0 0 1 0 0 1 1 1 1 0 0 2 0 1 1 1
31 gnat 0 0 1 0 1 0 0 0 0 1 0 0 6 0 0 0 6
32 goat 1 0 0 1 0 0 0 1 1 1 0 0 4 1 1 1 1
33 gorilla 1 0 0 1 0 0 0 1 1 1 0 0 2 0 0 1 1
34 gull 0 1 1 0 1 1 1 0 1 1 0 0 2 1 0 0 2
35 haddock 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 4
36 hamster 1 0 0 1 0 0 0 1 1 1 0 0 4 1 1 0 1
37 hare 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 0 1
38 hawk 0 1 1 0 1 0 1 0 1 1 0 0 2 1 0 0 2
39 herring 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 4
40 honeybee 1 0 1 0 1 0 0 0 0 1 1 0 6 0 1 0 6
41 housefly 1 0 1 0 1 0 0 0 0 1 0 0 6 0 0 0 6
42 kiwi 0 1 1 0 0 0 1 0 1 1 0 0 2 1 0 0 2
43 ladybird 0 0 1 0 1 0 1 0 0 1 0 0 6 0 0 0 6
44 lark 0 1 1 0 1 0 0 0 1 1 0 0 2 1 0 0 2
45 leopard 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
46 lion 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
47 lobster 0 0 1 0 0 1 1 0 0 0 0 0 6 0 0 0 7
48 lynx 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
49 mink 1 0 0 1 0 1 1 1 1 1 0 0 4 1 0 1 1
50 mole 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 0 1
51 mongoose 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
52 moth 1 0 1 0 1 0 0 0 0 1 0 0 6 0 0 0 6
53 newt 0 0 1 0 0 1 1 1 1 1 0 0 4 1 0 0 5
54 octopus 0 0 1 0 0 1 1 0 0 0 0 0 8 0 0 1 7
55 opossum 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 0 1
56 oryx 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 1 1
57 ostrich 0 1 1 0 0 0 0 0 1 1 0 0 2 1 0 1 2
58 parakeet 0 1 1 0 1 0 0 0 1 1 0 0 2 1 1 0 2
59 penguin 0 1 1 0 0 1 1 0 1 1 0 0 2 1 0 1 2
60 pheasant 0 1 1 0 1 0 0 0 1 1 0 0 2 1 0 0 2
61 pike 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 1 4
62 piranha 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 4
63 pitviper 0 0 1 0 0 0 1 1 1 1 1 0 0 1 0 0 3
64 platypus 1 0 1 1 0 1 1 0 1 1 0 0 4 1 0 1 1
65 polecat 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
66 pony 1 0 0 1 0 0 0 1 1 1 0 0 4 1 1 1 1
67 porpoise 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 1
68 puma 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
69 pussycat 1 0 0 1 0 0 1 1 1 1 0 0 4 1 1 1 1
70 raccoon 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
71 reindeer 1 0 0 1 0 0 0 1 1 1 0 0 4 1 1 1 1
72 rhea 0 1 1 0 0 0 1 0 1 1 0 0 2 1 0 1 2
73 scorpion 0 0 0 0 0 0 1 0 0 1 1 0 8 1 0 0 7
74 seahorse 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 4
75 seal 1 0 0 1 0 1 1 1 1 1 0 1 0 0 0 1 1
76 sealion 1 0 0 1 0 1 1 1 1 1 0 1 2 1 0 1 1
77 seasnake 0 0 0 0 0 1 1 1 1 0 1 0 0 1 0 0 3
78 seawasp 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 7
79 skimmer 0 1 1 0 1 1 1 0 1 1 0 0 2 1 0 0 2
80 skua 0 1 1 0 1 1 1 0 1 1 0 0 2 1 0 0 2
81 slowworm 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 3
82 slug 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 7
83 sole 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 4
84 sparrow 0 1 1 0 1 0 0 0 1 1 0 0 2 1 0 0 2
85 squirrel 1 0 0 1 0 0 0 1 1 1 0 0 2 1 0 0 1
86 starfish 0 0 1 0 0 1 1 0 0 0 0 0 5 0 0 0 7
87 stingray 0 0 1 0 0 1 1 1 1 0 1 1 0 1 0 1 4
88 swan 0 1 1 0 1 1 0 0 1 1 0 0 2 1 0 1 2
89 termite 0 0 1 0 0 0 0 0 0 1 0 0 6 0 0 0 6
90 toad 0 0 1 0 0 1 0 1 1 1 0 0 4 0 0 0 5
91 tortoise 0 0 1 0 0 0 0 0 1 1 0 0 4 1 0 1 3
92 tuatara 0 0 1 0 0 0 1 1 1 1 0 0 4 1 0 0 3
93 tuna 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 1 4
94 vampire 1 0 0 1 1 0 0 1 1 1 0 0 2 1 0 0 1
95 vole 1 0 0 1 0 0 0 1 1 1 0 0 4 1 0 0 1
96 vulture 0 1 1 0 1 0 1 0 1 1 0 0 2 1 0 1 2
97 wallaby 1 0 0 1 0 0 0 1 1 1 0 0 2 1 0 1 1
98 wasp 1 0 1 0 1 0 0 0 0 1 1 0 6 0 0 0 6
99 wolf 1 0 0 1 0 0 1 1 1 1 0 0 4 1 0 1 1
100 worm 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 7
101 wren 0 1 1 0 1 0 0 0 1 1 0 0 2 1 0 0 2